for a little project I have build a Python UI which should autostart on a Raspberry PI4 that has a DSI touch display connected to it. I'm currently running Raspbian on it but that can be changed if needed.

But I'm not able to get this to work. I found an old post about this problem (How to boot into own python script (GUI) only?) but the solutions don't work for me.

Since "nodm" is deprecated, I installed the newer "lightdm-autologin-greeter" Then I created an .xsession-file with the following content:

#!/usr/bin/env bash
exec openbox-session &
while true; do
  python3 /home/xxx/ui.py

and yeah.. No Python UI on my DSI screen. When I log in via RDP, the UI gets shown in the RDP-session instead.. I understood that RDP creates a new Xsession instead of using the existing one so now I'm wondering, why my UI won't start to the DSI screen.

I'm completely new to Xsessions and how Linux handles this so it might be a simple problem. Hope someone can help me out

  • What Pi? What OS?
    – Milliways
    Dec 30, 2023 at 12:06
  • Pi4, Raspbian. Edited my post
    – Grogak
    Dec 30, 2023 at 12:15
  • your description of the problem is unclear ... does the app work when started manually?
    – jsotola
    Dec 30, 2023 at 18:25
  • If you're running 'bookworm': you don't have X - you have Wayland. You can change from Wayland to X using raspi-config. There's a recent answer relevant to making that switch here. If it helps, consider an upvote - the other asshole didn't.
    – Seamus
    Dec 30, 2023 at 23:30

1 Answer 1


I don't know if this will help you. I took an old python script and modified it a little and ran some test on my RP 3 in a 7" touch screen and it seem to be what you are asking. I added a first line in $HOME/.profile that has a full path to my /home/pi/bin/dsphost.py. This puts a window on the display as a button which happens before anything else on the screen. Touching the button or mouse click on the button allows the screen to initialize. There are some side effects as the first line in $HOME/.profile needs to be committed out.

#!/usr/bin/env python
# Program name is dsphost.py.

import tkinter as tk

fp = open('/etc/hostname', 'r')
hn = fp.read().strip()

fp = open('/etc/os-release', 'r')
os = ((fp.readline().strip().split())[-1])[1:-2].capitalize()

fp = open('/etc/debian_version', 'r')
ver = fp.read().strip()

data = hn + " " + os + " " + ver

def click():
    with open('/home/pi/.profile', 'r+') as fp:
       line = fp.read()
       fp.write('#' + line)

mywindow = tk.Tk()
tk.Button(text = data, font=("Roboto 14"), command = click).pack()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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