-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?

Darth Vader
  • 4,206
  • 24
  • 45
  • 69

2 Answers2

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
Ingo
  • 42,107
  • 20
  • 85
  • 197
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.

aklingam
  • 974
  • 4
  • 16
  • 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