0

I want to achieve following:

run my GUI (made in Tkinter interface) application automatically as I boot the RPi (i.e. no desktop screen loading). But I want to be able kill the application so I can access the desktop though.

I have tried several methods which I found previously asked here, here and also here. I also played with adding my executable file in /home/pi/.config./autostart folder - no effect unfortunately.

I'm getting little desperate as this at first seemed as an easy task with lots of support online. However, after watching several tutorial, I have been stuck on this for days and cannot get it running properly.

What do I need to have it set in Boot Options (sudo raspi-config)?

Here is the code of the GUI app:

from Tkinter import *

root = Tk()
root.title('Scanner')

# create the top container
top_frame = Frame(root)
top_frame.pack( side = TOP )

scan_pcb=Label(top_frame,text='SCANNED CODE: ')
scan_pcb.grid(row=0,column=0)

pcb_entry=Entry(top_frame,background='white')
pcb_entry.grid(row=0,column=1)
pcb_entry.focus_set() 

# create the left container
left_frame = Frame(root)
left_frame.pack( side = LEFT )

A_label=Label(left_frame,text='A')
A_label.grid(row=0,column=0)
A_entry=Entry(left_frame,background='white')
A_entry.grid(row=0,column=1)

B_label=Label(left_frame,text='B')
B_label.grid(row=1,column=0)
B_entry=Entry(left_frame,background='white')
B_entry.grid(row=1,column=1)

C_label=Label(left_frame,text='C')
C_label.grid(row=2,column=0)
C_entry=Entry(left_frame,background='white')
C_entry.grid(row=2,column=1)

# create the right container
right_frame = Frame(root)
right_frame.pack( side = RIGHT )

D_label=Label(right_frame,text='D')
D_label.grid(row=0,column=2)
D_entry=Entry(right_frame,background='white')
D_entry.grid(row=0,column=3)

E_label=Label(right_frame,text='E')
E_label.grid(row=1,column=2)
E_entry=Entry(right_frame,background='white')
E_entry.grid(row=1,column=3)

E_label=Label(right_frame,text='F')
E_label.grid(row=2,column=2)
E_entry=Entry(right_frame,background='white')
E_entry.grid(row=2,column=3)

root.mainloop()

Here is the desktop shortcut text file:

[Desktop Entry]
Name=SCANNER
Comment=My application which does this
Icon=/home/pi/Desktop/scan.png
Exec=python /home/pi/Desktop/SCANNER.py
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;

Perhaps the methods mentioned in the links are outdated? Can anybody share relevant, precise and consise procedure for autorun boot, please?

Thank you very much.

Staflik
  • 3
  • 2

2 Answers2

1

Put the command line from your .desktop file into /home/pi/.config/lxsession/LXDE-pi/autostart or /etc/xdg/lxsession/LXDE/autostart, whichever you use on your system.

/home/pi/.config./autostart directory doesn't seem to exist or be used on Raspbian.

Dmitry Grigoryev
  • 27,928
  • 6
  • 53
  • 144
1

From Raspberry Pi documentation:

Edit file /etc/rc.local sudo nano /etc/rc.local

Add your command bellow the comment, but leave the line exit 0 at the end of file.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

python /home/pi/Desktop/SCANNER.py &

exit 0

Save. Make your script executable: sudo chmod 755 /home/pi/Desktop/SCANNER.py and restart Raspberry: sudo reboot now Your script should run after boot

Don't forget to add & after your command if your program will run in infinite loop.

Koxo
  • 151
  • 2
  • 1
    This is unlikely to work with a foreground GUI app. The usual approach there is to use the desktop environment's autostart configuration together with GUI autologin (so a user is logged in automatically at boot, and when their desktop starts, the application launches). If you search around here for "LXDE" and "autostart" you'll find examples etc. PIXEL, the current Raspbian default desktop, is a fork of LXDE. Beware not to follow anything too old; also, I think a common problem is the location of the right autostart config. – goldilocks Nov 29 '18 at 14:42
  • @Koxo Ok, thanks. I have actually tried using rc.local and that have not worked at all. – Staflik Nov 29 '18 at 15:57
  • @goldilocks Alright, so I have my .desktop file - when I double click on it, GUI runs perfectly. I found that /etc/xdg/lxsession/LXDE-pi is the place to look at. Here the autostart file looks like this:

    @lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi @xscreensaver -no-splash point-rpi

    So how do change content so it runs my .desktop file automatically? This thread suggest a method but I do not understand it fully. Would you please explain it to me if possible?

    – Staflik Nov 29 '18 at 15:59
  • Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using it. – Ingo Dec 07 '18 at 17:59