Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62864 > unrolled thread

Tkinter problem: TclError> couldn't connect to display ":0

Started byMichael Matveev <mischamv@googlemail.com>
First post2013-12-29 12:20 -0800
Last post2013-12-30 00:59 -0500
Articles 7 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Tkinter problem: TclError> couldn't connect to display ":0 Michael Matveev <mischamv@googlemail.com> - 2013-12-29 12:20 -0800
    Re: Tkinter problem: TclError> couldn't connect to display ":0 Chris Angelico <rosuav@gmail.com> - 2013-12-30 08:40 +1100
    Re: Tkinter problem: TclError> couldn't connect to display ":0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-30 10:22 +1100
      Re: Tkinter problem: TclError> couldn't connect to display ":0 Chris Angelico <rosuav@gmail.com> - 2013-12-30 10:30 +1100
        Re: Tkinter problem: TclError> couldn't connect to display ":0 Steven D'Aprano <steve@pearwood.info> - 2013-12-30 03:29 +0000
          Re: Tkinter problem: TclError> couldn't connect to display ":0 Chris Angelico <rosuav@gmail.com> - 2013-12-30 15:11 +1100
          Re: Tkinter problem: TclError> couldn't connect to display ":0 Jason Swails <jason.swails@gmail.com> - 2013-12-30 00:59 -0500

#62864 — Tkinter problem: TclError> couldn't connect to display ":0

FromMichael Matveev <mischamv@googlemail.com>
Date2013-12-29 12:20 -0800
SubjectTkinter problem: TclError> couldn't connect to display ":0
Message-ID<b6e02836-6f08-4e9f-bd55-201c22ff42b3@googlegroups.com>
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"



thanks for helping out.

greets.
Mike

[toc] | [next] | [standalone]


#62868

FromChris Angelico <rosuav@gmail.com>
Date2013-12-30 08:40 +1100
Message-ID<mailman.4707.1388353266.18130.python-list@python.org>
In reply to#62864
On Mon, Dec 30, 2013 at 7:20 AM, Michael Matveev
<mischamv@googlemail.com> wrote:
> 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"

Worked for me on an installed Debian, inside Xfce with xfce4-terminal.

1) What version of Python are you running?
2) Are you running inside some kind of graphical environment?
3) Do you have any sort of permissions/environment change happening? I
get an error like that if I try "sudo python" without any sort of
guard.

ChrisA

[toc] | [prev] | [next] | [standalone]


#62871

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-12-30 10:22 +1100
Message-ID<52c0aed1$0$29981$c3e8da3$5496439d@news.astraweb.com>
In reply to#62864
Michael Matveev wrote:

> 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.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#62872

FromChris Angelico <rosuav@gmail.com>
Date2013-12-30 10:30 +1100
Message-ID<mailman.4709.1388359820.18130.python-list@python.org>
In reply to#62871
On Mon, Dec 30, 2013 at 10:22 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> 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.

With SSH, that's usually just "ssh -X target", and it'll mostly work.
But there are potential issues with .Xauthority, which is why the sudo
example fails.

ChrisA

[toc] | [prev] | [next] | [standalone]


#62873

FromSteven D'Aprano <steve@pearwood.info>
Date2013-12-30 03:29 +0000
Message-ID<52c0e898$0$2877$c3e8da3$76491128@news.astraweb.com>
In reply to#62872
On Mon, 30 Dec 2013 10:30:11 +1100, Chris Angelico wrote:

> On Mon, Dec 30, 2013 at 10:22 AM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> 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.
> 
> With SSH, that's usually just "ssh -X target", and it'll mostly work.

Holy cow, it works! Sloooooooowly, but works.


steve@runes:~$ ssh -X ando.pearwood.info
steve@ando.pearwood.info's password: 
Last login: Mon Dec 30 10:10:13 2013 from orac
[steve@ando ~]$ python2.7 test.py 
[steve@ando ~]$ 


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#62874

FromChris Angelico <rosuav@gmail.com>
Date2013-12-30 15:11 +1100
Message-ID<mailman.4710.1388376680.18130.python-list@python.org>
In reply to#62873
On Mon, Dec 30, 2013 at 2:29 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> On Mon, 30 Dec 2013 10:30:11 +1100, Chris Angelico wrote:
>
>> On Mon, Dec 30, 2013 at 10:22 AM, Steven D'Aprano
>> <steve+comp.lang.python@pearwood.info> wrote:
>>> 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.
>>
>> With SSH, that's usually just "ssh -X target", and it'll mostly work.
>
> Holy cow, it works! Sloooooooowly, but works.
>
>
> steve@runes:~$ ssh -X ando.pearwood.info
> steve@ando.pearwood.info's password:
> Last login: Mon Dec 30 10:10:13 2013 from orac
> [steve@ando ~]$ python2.7 test.py
> [steve@ando ~]$

On a LAN, it's not even slow! I've actually run VLC through ssh -X and
watched a DVD that was in a different computer's drive. That was fun.

You can even get a Windows X server and run Linux GUI programs on a
Windows client. *Very* useful if you're working with both types of
computer.

ChrisA

[toc] | [prev] | [next] | [standalone]


#62876

FromJason Swails <jason.swails@gmail.com>
Date2013-12-30 00:59 -0500
Message-ID<mailman.4711.1388383522.18130.python-list@python.org>
In reply to#62873

[Multipart message — attachments visible in raw view] — view raw

On Sun, Dec 29, 2013 at 10:29 PM, Steven D'Aprano <steve@pearwood.info>wrote:

> On Mon, 30 Dec 2013 10:30:11 +1100, Chris Angelico wrote:
>
> > On Mon, Dec 30, 2013 at 10:22 AM, Steven D'Aprano
> > <steve+comp.lang.python@pearwood.info> wrote:
> >> 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.
> >
> > With SSH, that's usually just "ssh -X target", and it'll mostly work.
>
> Holy cow, it works! Sloooooooowly, but works.
>

I usually use "ssh -Y".  The -Y argument toggles trusted forwarding.  From
the ssh man-page:

     -Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are
not subjected to the X11
             SECURITY extension controls.

I've found -Y is a bit faster than -X in my experience (I've never really
had many problems with X-forwarding on LANs in my experience -- even with
OpenGL windows)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web