California
Posts: 217
Joined: Sat Jun 06, 2015 2:33 pm

How to run GUI application at boot

Sat Sep 23, 2017 11:45 am

Hello, I have a well working GUI application (PYQT4), which I would like to have started at boot of the RPi.
Some instructions from links below were followed but with no luck at all. My app is in "/home/pi/Project/Master_06.py".
https://www.dexterindustries.com/howto/ ... pberry-pi/
https://www.dexterindustries.com/howto/ ... t-startup/
What am I doing wrong?

Regards

User avatar
topguy
Posts: 7229
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How to run GUI application at boot

Sat Sep 23, 2017 1:32 pm

None of the guides you link to are suitable for starting a GUI program.
They start the program before the X-server and desktop has loaded so your program fails to start.

viewtopic.php?t=131760

User avatar
karrika
Posts: 1317
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: How to run GUI application at boot

Sat Sep 23, 2017 1:42 pm

I have a similar desire to start the RPi-InfoScreen application at startup.

By adding a file called /etc/xdg/autostart/RPi-infoscreen.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=RPi-infoscreen
Comment=Kivy RPI Infoscreen
NoDisplay=false
Exec=/usr/bin/lxterminal -e /home/pi/startKivy.sh
NotShowIn=GNOME;KDE;XFCE;
It will start a command line window and start my application that takes over the whole screen. The command line program is at /home/pi/startKivy.sh

Code: Select all

#!/bin/bash
cd /home/pi/RPi-InfoScreen-Kivy
/usr/bin/python main.py
Image

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: How to run GUI application at boot

Sat Sep 23, 2017 2:19 pm

Ha. Good piece of software to use as an example! :D
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

California
Posts: 217
Joined: Sat Jun 06, 2015 2:33 pm

Re: How to run GUI application at boot

Sat Sep 23, 2017 5:20 pm

Thanks for help, obviously I am stil missing something. I can see CPU usage jumps over 20% but nothing happends.

/etc/xdg/autostart/SCADA.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=SCADA         
Comment=SCADA app          
NoDisplay=false
Exec=/usr/bin/lxterminal -e /home/pi/Project/startMaster.sh
NotShowIn=GNOME;KDE;XFCE;

/home/pi/project/startMaster.sh

Code: Select all

#!/bin/bash
cd /home/pi/Project
/usr/bin/python Master_06.py

User avatar
karrika
Posts: 1317
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: How to run GUI application at boot

Sat Sep 23, 2017 6:37 pm

elParaguayo wrote:
Sat Sep 23, 2017 2:19 pm
Ha. Good piece of software to use as an example! :D
Lol. It has been running in my hallway 24/7 since I added the bus displays to your project. It is almost in daily use. Very handy when you also see all traffic delays and cancellations. Thanks for creating it.

User avatar
karrika
Posts: 1317
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: How to run GUI application at boot

Sat Sep 23, 2017 7:57 pm

California wrote:
Sat Sep 23, 2017 5:20 pm
Thanks for help, obviously I am stil missing something. I can see CPU usage jumps over 20% but nothing happends.

/etc/xdg/autostart/SCADA.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=SCADA         
Comment=SCADA app          
NoDisplay=false
Exec=/usr/bin/lxterminal -e /home/pi/Project/startMaster.sh
NotShowIn=GNOME;KDE;XFCE;

/home/pi/project/startMaster.sh

Code: Select all

#!/bin/bash
cd /home/pi/Project
/usr/bin/python Master_06.py
Can you start the script file by typing

Code: Select all

/home/pi/Project/startMaster.sh
It has to be made executable.
chmod +x /home/pi/Project/startMaster.sh

California
Posts: 217
Joined: Sat Jun 06, 2015 2:33 pm

Re: How to run GUI application at boot

Sat Sep 23, 2017 8:16 pm

Hm, it doesn't work ...

klricks
Posts: 8025
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to run GUI application at boot

Sat Sep 23, 2017 9:39 pm

California wrote:
Sat Sep 23, 2017 8:16 pm
Hm, it doesn't work ...
Have you tried using autostart as shown in the link in the 1st reply by topguy?

Code: Select all

nano /home/pi/.config/lxsession/LXDE-pi/autostart
Your entry in autostart should look something like this added to the end of what's there already:

Code: Select all

@lxterminal -e python /home/pi/Project/Master_06.py
If Python 3 then use python3 in above.
Last edited by klricks on Sun Sep 24, 2017 12:47 am, edited 1 time in total.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Martin Frezman
Posts: 1009
Joined: Mon Oct 31, 2016 10:05 am

Re: How to run GUI application at boot

Sun Sep 24, 2017 12:01 am

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
sudo??????????????????????????????

Note that in this case (*) it is not only unnecessary, but is dangerous. It is dangerous because you (usually) end up with these files owned by root - when they should obviously be owned by 'pi' - and then later on when you edit them the right way, you wonder why you get "permission denied" messages (and then you end up posting threads to this forum asking why things don't work).

(*) Specifically, using "sudo' to edit configuration files located in pi's home directory.
If this post appears in the wrong forums category, my apologies.

klricks
Posts: 8025
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to run GUI application at boot

Sun Sep 24, 2017 12:55 am

Martin Frezman wrote:
Sun Sep 24, 2017 12:01 am
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
sudo??????????????????????????????

Note that in this case (*) it is not only unnecessary, but is dangerous. It is dangerous because you (usually) end up with these files owned by root - when they should obviously be owned by 'pi' - and then later on when you edit them the right way, you wonder why you get "permission denied" messages (and then you end up posting threads to this forum asking why things don't work).

(*) Specifically, using "sudo' to edit configuration files located in pi's home directory.
I edited my post to remove sudo.
In this case it does not matter as the ownership of an existing file is not changed by sudo nano..... but it is a bad habit.
If a new file is created with sudo nano then it will be owned by root wherever it is located and that could cause problems later on.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

California
Posts: 217
Joined: Sat Jun 06, 2015 2:33 pm

Re: How to run GUI application at boot

Sun Sep 24, 2017 6:16 am

klricks wrote:
Sat Sep 23, 2017 9:39 pm
California wrote:
Sat Sep 23, 2017 8:16 pm
Hm, it doesn't work ...
Have you tried using autostart as shown in the link in the 1st reply by topguy?

Code: Select all

nano /home/pi/.config/lxsession/LXDE-pi/autostart
Your entry in autostart should look something like this added to the end of what's there already:

Code: Select all

@lxterminal -e python /home/pi/Project/Master_06.py
If Python 3 then use python3 in above.
Thanks everybody, solution posted above works as expected.
With best regards,
Vlado

Return to “Python”