I am building my first tkinter application which works perfectly until I try to auto start it at boot. I have researched this topic and tried numerous things but nothing works correctly.
I am running RPi4 with raspbian buster, python 3.7.3 and want this application to run on the RPI touch screen without requiring a user to login.
I found this link which looks like I should be able to start my app from the terminal without loading the desktop by invoking a window manager like X openbox or something similar. I did find that if I create a ~/.xinitrc file and add the following line, I can start the window from the command prompt by typing startx.
exec sudo /usr/bin/python3 /home/$user_name/robot/robot.py
I have tried starting the program using systemd but to no avail. Would certainly appreciate some help on this.
Ok so after a week of beating my head on the desk I finally found a solution that works perfect. This loads the GUI application before the command prompt login with the raspberry pi GUI disabled and when the application is closed for any reason it returns to a logged out command prompt.
I want to clarify that I have disabled the default pi user and have created another user account for this project. I have located my entire python/tkinter project in the '/home/$user_name/robot' folder and have given this new user the same permissions as the pi user.
Enable boot to command line only
Setup the system initrc to load the application
Comment out existing lines and add the following (change path to your script)
Create a systemd unit file to startup X window and run the application
In the new file add the following lines (:0.0 is RPi Display Port and Xauthority points to the user profile you wish to run the app under)
Reload the unit files and enable the new unit
Can check the status of the new service by the following command
Now reboot the system and the python application with tkinter gui should be displayed before the command prompt is shown. If the app is exited for any reason, the command prompt login should be shown.
Thanks to @acw1668 for sharing THIS LINK which helped a ton. THIS is a great reference for systemd and unit file details.