0

Im using openbox to control a tkinter app. My app is t.py and is located in ~.

This is my ~/.config/openbox/autostart:

python3 ~/t.py

This is t.py:

import tkinter as tk

root = tk.Tk()
label = tk.Label(root, text="Hello")
label.pack()
root.mainloop()

When I run sudo startx, I can see the cursor pop up then hide, but after that its just a black screen. I am running these commands over ssh as well. I had this working before with a separate .py file but can no longer get it to work. I am running this on a Raspberry Pi Zero 2 W with a HDMI screen. The Pi is installed with the latest Raspberry Pi OS Lite.

4
  • can you run it manually in ssh? Usually ssh works without graphics mode and it can't display any GUI programs - so it can't execute tkinter which needs graphics mode. Commented Feb 23 at 1:24
  • sudo may run as root which has different home folder - and usually it needs to use /full/path/to/python3 /full/path/to/script. In script you may also run pwd >> text.log to see what working directory it uses to run all code. Commented Feb 23 at 1:26
  • What do you mean run it manually? Commented Feb 23 at 6:06
  • "manually" means to write this command in ssh/terminal/bash on your own and see if it works or gives error messages. And later you could try to run in in any script which you don't start on your own (but system run it automatically). And it may need to write some information to file/log to see if system runs it without errors. Sometimes system runs code as different user, with different privileges, in different folder - and this sometimes problem because code doesn't find some elements or has no privileges to run something. And it needs to use /full/path/to/command, /full/path/to/file Commented Feb 23 at 19:47

2 Answers 2

0

As per the man page for openbox, you need to rename the startup script as autostart.sh
and also make it executable using
chmod +x ~/.config/openbox/autostart.sh.

Finally, ensure you put an & sign at the end of the command.

python ~/t.py &

inside the autostart.sh file.

Sign up to request clarification or add additional context in comments.

11 Comments

This still doesn't solve the issue for me.
Are you able to launch startx without sudo? If you launch with sudo, ~/ will be the path /home/root instead of your username, like /home/pepper. This would mean openbox will try to launch the command python /home/root/t.py which doesn't exist.
When I attempt to launch it with startx and no sudo, I get the error (EE) xf86OpenConsole: Cannot open virtual console 3 (Permission denied)
I should also note that i'm doing this over ssh.
Okay. Do one thing. Instead of providing the path as ~/t.py in the script file, use the absolute path: /home/pepper/t.py Replace pepper with your username on the Pi. And run startx as sudo.
|
0

Try using the following approach which does not depend on what window manager is used:

  • create a <anyname>.desktop file inside ~/.config/autostart/ folder
    e.g. ~/.config/autostart/demo.desktop

  • enter the following content inside the above file:

[Desktop Entry]
Type=Application
Exec=/bin/bash -c "/usr/bin/python3 $HOME/t.py"

The above works in my VM running Debian Bullseye with Raspberry Pi Desktop.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.