-2

I want to autostart a Python script that starts a Tkinter GUI at boot up.

The working terminal command to start the script is python3 /home/pi/Documents/slincam/slincam_menu.py.

I added this command to /etc/rc.local, but the program doesn't show up at boot up. Strangely when I type sudo /etc/rc.local in the terminal, the program starts.

Please, does someone know a solution for this?

9
  • There are hundreds of similar questions. Answers warn NOT to use /etc/rc.local. To compound the issue you CAN NOT start a GUI program on boot, using ANY method - because there is NO Desktop until login.
    – Milliways
    Aug 24 '20 at 3:57
  • 1
    Does this answer your question? Running a Python script at startup
    – aklingam
    Aug 24 '20 at 4:22
  • @Milliways Ok, but is there any way to autostart a GUI-program after the desktop loaded?
    – Neldela
    Aug 24 '20 at 7:01
  • 1
    @Neldela look at systemd services
    – Swedgin
    Aug 24 '20 at 8:31
  • Add a line to /etc/xdg/lxsession/LXDE-pi/autostart to autostart your GUI.
    – Dougie
    Aug 24 '20 at 10:09
1

A systemd Unit file could do it. Try this:

rpi ~$ sudo systemctl --force --full edit slincam_menu.service

In the empty editor insert these statements, save them and quit the editor:

[Unit]
Description=Slincam Menu
After=graphical.target

[Service]
User=pi
WorkingDirectory=/home/pi
Environment=DISPLAY=:0
ExecStart=/usr/bin/python3 /home/pi/Documents/slincam/slincam_menu.py

[Install]
WantedBy=graphical.target

Enable the new service and reboot:

rpi ~$ sudo systemctl enable slincam_menu.service
rpi ~$ sudo systemctl reboot

Check with:

rpi ~$ systemctl status slincam_menu.service
0

I generally use crontab.. You may add your command to crontab in the following steps.

  1. sudo crontab - e
  2. Open using your favourite text editor
  3. At the bottom add the line: @reboot python3 /home/pi/Documents/slincam/slincam_menu.py

Before doing so, please ensure file permissions.

1
  • crontab is no good at all for a GUI program. It runs the @reboot lines before the GUI is active.
    – Dougie
    Aug 24 '20 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.