I'm using raspberry pi 3 and i have made gui script with two button and one image, it is running well if we run using command:

sudo python
sudo python gui.py

But i want to automatic run this gui script after i am logged in to raspberry pi desktop window. I don't know how to do this? Please reply. Thanks in advance.

1 Answer 1


Create in home directory folders ~/.config/autostart by running following command:

mkdir -p ~/.config/autostart

and create inside of this directory text file mygui.desktop

touch ~/.config/autostart/mygui.desktop

then add to this file description of your program, something like this

[Desktop Entry]
Exec=/usr/bin/python gui.py

More on creating .desktop file here

If you really need to run GUI program as root (???) then you need to use desktop's replacement of sudo, it is gksu

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .