单击桌面图标以在Raspbian中执行python脚本(Click desktop icon to execute python script in Raspbian)

编程入门 行业动态 更新时间:2024-10-26 19:26:14
单击桌面图标以在Raspbian中执行python脚本(Click desktop icon to execute python script in Raspbian)

我试图制作一个.bat或.exe文件来执行linux(Raspbian)中的python脚本。 我想在桌面上有一个点击(触摸屏)的图标,然后执行python脚本。

python脚本需要'sudo'授权...所以如果我想在终端中运行:

sudo python filelocation/name.py

谢谢!

I am trying to make either a .bat or .exe file to execute a python script in linux (Raspbian). I would want to have an icon on the desktop which will be clicked (touch screen) and will then execute the python script.

The python script would need 'sudo' authorization... so if I wanted to run in terminal:

sudo python filelocation/name.py

Thanks!

最满意答案

使用.desktop文件作为nodakai已经提到过。

要使用root权限执行python文件

使用像gksudo python program.py这样的东西。 这将在正常窗口中询问用户密码,不涉及终端。 如果不要求用户输入密码,请考虑sudoers文件中的条目,并使用通常的sudo python program.py 。 (如果使用此方法,请确保您的程序不允许用户执行他们想要的任何操作,但只能执行您希望用户能够以root用户身份执行的特定任务。)

Use a .desktop file as nodakai already mentioned.

To have the python file executed with root permissions, either

use something like gksudo python program.py. This will ask the user for the password in a normal window, no terminal involved. if the user shall not be asked for a password, consider an entry in the sudoers file, and use the usual sudo python program.py. (If you use this, make sure your program doesn't allow the user to do whatever they want, but only does the specific tasks you want the user to be able to do as root.)

更多推荐

本文发布于:2023-08-02 22:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1381535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   脚本   桌面图标   python   Raspbian

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!