Page 1 of 1

Tkinter execute from ssh gives error

Posted: Sat Nov 05, 2016 7:49 pm
by Canedje
I do have a ssh connection to my RPI3.
I did write a small and easy Tkinter program by the ssh connection:

Code: Select all

from Tkinter import *
# if you are working under Python 3, comment the previous line and comment out the following line
#from tkinter import *

root = Tk()

w = Label(root, text="Hello Tkinter!")
w.pack()
print ('test ')

root.mainloop()

There is a monitor connected to the HDMI port and is showing the RPI screen.
I try to achieve that the Tkinter programm shows up at the monitor by the HDMI by executing from the ssh connection.
If I try to runt it from the ssh connection the next error occurs:

python gui.py

Code: Select all

Traceback (most recent call last):
  File "gui.py", line 5, in <module>
    root = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
Than I found on internet to set: export DISPLAY=:0.0
before executing

Now the error shows:

Code: Select all

No protocol specified
No protocol specified
Traceback (most recent call last):
  File "gui.py", line 5, in <module>
    root = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"

It looks like it is not recognizing the monitor connection by HDMI.

What am I doing wrong?
How to start this Tkinter programm from ssh connection but running on the HDMIconnection?

EDIT:
I did found the solution.

First you need to start up in GUI mode after reboot
You need to enter the GUI mode under the same login as the ssh connection
the you need to execute at the ssh connection: export DISPLAY=:0.0

Than running the GUI programm

Re: Tkinter execute from ssh gives error

Posted: Wed Jan 17, 2018 10:37 pm
by pintun
Hello,

same problem here.

What does it mean:
First you need to start up in GUI mode after reboot
You need to enter the GUI mode under the same login as the ssh connection
?

Re: Tkinter execute from ssh gives error

Posted: Sun Apr 19, 2020 4:17 am
by pravinyouwin
hello!
I ran in to same issue here while running GUI at start up of PI. can someone help me please?

Code: Select all

Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyno display found. Using :0.0
 Traceback (most recent call last):
  File "/home/pi/.vent/breath.py", line 162, in <module>
    root=tk.Tk()
  File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"  

I also tried different solutions suggested online, but the above error displayed in cronlog when i tried to reboot.
when user run the .py code manually, GUI app runs good. But I need this to work at start up without intervention of user.

Code: Select all

sudo apt-get install x11-apps

xhost +localhost

export DISPLAY=:0.0

Re: Tkinter execute from ssh gives error

Posted: Sun Apr 19, 2020 9:26 am
by B.Goode
pravinyouwin wrote:
Sun Apr 19, 2020 4:17 am
hello!
I ran in to same issue here while running GUI at start up of PI. can someone help me please?

Code: Select all

Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyno display found. Using :0.0
 Traceback (most recent call last):
  File "/home/pi/.vent/breath.py", line 162, in <module>
    root=tk.Tk()
  File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"  

I also tried different solutions suggested online, but the above error displayed in cronlog when i tried to reboot.
when user run the .py code manually, GUI app runs good. But I need this to work at start up without intervention of user.

Code: Select all

sudo apt-get install x11-apps

xhost +localhost

export DISPLAY=:0.0


The initial query in this thread was -
I do have a ssh connection to my RPI3.
I did write a small and easy Tkinter program by the ssh connection:


Your query is:
I ran in to same issue here while running GUI at start up of PI.

That is not 'the same issue'.


In your case the solution is to invoke your script from the lxde autostart configuration.