Autostart a python GUI script on a Raspberry Pi

I have a application written in python with tkinter that I want to autostart every time the pi user logs into LXDE on a raspberry pi.

I have edited /etc/xdg/lxsession/LXDE-pi/autostart and added the following line:

@/usr/bin/python3 /home/pi/kiosk/kiosk.py

and this doesn’t start the application. Any suggestions?

What I do is drop .xinitrc (if it doesn’t exist) into ~/, and have that execute anything I want to run on login. It’s been some time since I messed with it though, and I remember it being a bit finicky, so your mileage may vary. Similarly, ~/.bashrc will run things on console login, if you use that.

Upon further reflection, I don’t think that will do what you want, it would likely run before LXDE actually starts…I’ll leave it for posterity though.

This thread seems to have figured it out, I’m not sure what they are doing differently than you though. Maybe check that your .py file has executable permissions?

1 Like

@zachaq

Thanks for the suggestions.

The python script is executable. And since the auto start file may be executed as root I ensured that all users have read and execute permissions to the file. However, it still doesn’t work. Not sure what is going on.

I am working on a kiosk style application, and would really like to have it autostart after x windows starts on the PI.

Put an echo at the top of the autostart file. Pipe the output from echo to a location with no / minimal restrictions. The temporary directory seems like a reasonable place. If the file shows up with the expected contents then you know the autostart file is being processed and you know there is a problem with the python3 line. If the file does not show up there is either a problem with the echo line or the autostart file is not being processed.

2 Likes

Okay, I have solved my problem, but thought it would be helpful to post the solution in case anyone comes across this post in a google search.

So here is the physical configuration I was attempting to get this to work on

Raspberry Pi 2
Raspbian Jesse, 2015-09-24
Official Raspberry Pi 7" Touchscreen

After testing it became clear that the autostart script in /etc/xdg/lxsession/LXDE-pi/ was not being run when I started the pi (auto boot into X windows and auto login as Pi)

So I did a search for autostart and discovered there was an identical script in
/home/pi/.config/lxsession/LXDE-pi

By identical I mean it has the exact same commands the /etc/xdg/… file did before my OP edits. This makes me think that only one of these scripts is being run when the system boots. And that appears to be the case because when I added the line I tried in my OP above the machine started booting and running my python script on boot.

Thanks for all of the assistance guys! F2f

3 Likes