I am running a python tkinter gui that I need to launch on boot. I am using a raspberry pi 4b running Debian bookworm with the official 7″ touchscreen. I have successfully used systemd to launch my gui on boot without the desktop environment appearing first. Here is the setup of my systemd file:
[Unit]
Description=Autostart Tkinter GUI
[Service]
Environment=Display=:0.0
Environment=XAUTHORITY=/home/usr/.Xauthority
ExecStart=/bin/bash -c 'source /home/usr/path_to_venv && cd /home/usr/path_to_file_directory && DISPLAY=:0.0 python my_tkinter_gui.py'
Restart=always
RestartSec=5s
KillMode=process
TimeoutSec=infinity
[Install]
WantedBy=graphical.target
This works perfectly for launching my tkinter gui. It also gives me the ability to exit my tkinter gui (an aspect of the program) and go to the pi’s desktop environment.
My problem is that I want screen blanking to work. I have turned screen blanking on through the configuration setting in the pi’s desktop environment. I have also turned it on using sudo raspi-config
when I ssh into the pi. The screen blanking works perfectly when I am not running any gui, but it no longer works when I run the gui. It used to work when I manually ran the gui, but after using systemd to launch the gui, screen blanking does not work for either scenario.
I have attempted to set screen blanking using xset
but have had no success. When I run xset q
to see current setting, I get the error ‘xset: unable to open display “”.’ If I export the display using export DISPLAY=:0.0
, I am able to run xset q
. However, once I edit the settings, nothing happens. Furthermore, the DPMS section says, “DPMS (Energy Star): Server does not have the DPMS Extension.” I have also tried adding an xset command to my systemd to no avail. The systemd runs fine and launches the tkinter gui, but there is not screen blanking.
I have spent hours on this and have gotten nowhere. Any help would be greatly appreciated. This is part of a time-sensitive project.
I am a beginner dealing with stuff, so pardon any glaringly obvious mistakes.
wakwak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.