NRav
NRav

Reputation: 407

Click desktop icon to execute python script in Raspbian

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!

Upvotes: 1

Views: 12329

Answers (3)

Marian
Marian

Reputation: 6257

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.)

Upvotes: 3

nodakai
nodakai

Reputation: 8033

I've never used Raspbian myself, but I guess you can follow the standard procedure to add a custom icon to your desktop:

Upvotes: 4

Joran Beasley
Joran Beasley

Reputation: 113998

name.py

#!/bin/python
.....

then set the permissions (all the following commands are done in the terminal)

$ chmod a+x name.py

then you can run it as

$ ./name.py

if you wanted to run it as sudo you would do

$ sudo ./name.py

Upvotes: -1

Related Questions