Michael said:
Hi,
I use live Debian on VM and trying to compile this code.
import Tkinter
root = Tkinter.Tk()
root.title("Fenster 1")
root.geometry("100x100")
root.mainloop()
The shell gives out that kind of message:
File "test.py", line 5, in <module>
root = Tkinter.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive,
wantobjects, useTk, sync, use) _tkinter.TclError: couldn't connect to
display ":0"
Are you using ssh to connect to the system? If I create a file and run it
directly from the machine I am physically sitting at, it works fine and the
window is displayed as expected:
[steve@ando ~]$ cat test.py
import Tkinter
root = Tkinter.Tk()
root.title("Fenster 1")
root.geometry("100x100")
root.mainloop()
[steve@ando ~]$ python2.7 test.py
[steve@ando ~]$
But if I ssh to the machine, I get an error (although a different error from
you):
steve@orac:~$ ssh ando
steve@ando's password:
Last login: Thu Dec 12 19:27:04 2013 from 203.7.155.68
[steve@ando ~]$ python2.7 test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
root = Tkinter.Tk()
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1685, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive,
wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
If I set the $DISPLAY environment variable, it works for me:
[steve@ando ~]$ export DISPLAY=":0"
[steve@ando ~]$ python2.7 test.py
[steve@ando ~]$ logout
Connection to ando closed.
But ando is the machine I am physically seated at, so it's not surprising
that I can see the window on the X display. If I go the other way, and try
to run the code on orac (the remote machine), I get the same error as you:
steve@orac:~$ export DISPLAY=":0"
steve@orac:~$ python2.6 test.py
No protocol specified
Traceback (most recent call last):
File "test.py", line 2, in <module>
root = Tkinter.Tk()
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1646, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive,
wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"
So you need to X-forward from the remote machine to the machine you are
physically on, or perhaps it's the other way (X is really weird). I have no
idea how to do that, but would love to know.