Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Tk OSX couldn't connect to display :0

by Washizu (Scribe)
on Nov 26, 2006 at 18:06 UTC ( #586134=perlquestion: print w/replies, xml ) Need Help??
Washizu has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to run a Perl/Tk app on Mac OSX 10.4.8 (Tiger) and ran into an error message when I tried to create a new MainWindow object.
couldn't connect to display ":0" at usr/local/ActivePerl-5.8/lib/Tk/Ma line 55
So I tried a the basic MainWindow example script and came up with the same error.
use Tk; # Main Window my $mw = new MainWindow; my $label = $mw -> Label(-text=>"Hello World") -> pack(); my $button = $mw -> Button(-text => "Quit", -command => sub { exit }) -> pack(); MainLoop;
The Tk module is up to date, so I'm not sure what is going on here Any ideas?

Odd Man In: Guns and Game Theory

Replies are listed 'Best First'.
Re: Tk OSX couldn't connect to display :0
by neniro (Priest) on Nov 26, 2006 at 18:47 UTC
    Start your first.

    EDIT:If you work in a terminal-window you can type open /Applications/Utilities/ to start the

      Thanks for your help. I thought X11 was installed, because when I tried to install it from apple's site it said I already had it. It turned out I had to install it from the installation DVD and now it works. Of course, my app doesn't run exactly right but it at least runs now!

      Odd Man In: Guns and Game Theory

Re: Tk OSX couldn't connect to display :0
by Fletch (Chancellor) on Nov 26, 2006 at 18:56 UTC

    Aside from making sure that is running, check that you can run another X program from a Terminal window (say xterm and/or xhost). Some things can confuzzle the xauth authentication, such as disappearing network connections (disconnecting from a WiFi network, or disconnecting a modem connection).


      I don't recall if it's actually necessary on OSX, but some time ago I ended up putting the following in my .profile or .bashrc so I never have to think about it ever again:

      export DISPLAY=localhost:0.0

      s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

        Which could be OK in your case, but if you use ssh and X forwarding, your exported DISPLAY will overwrite the special one that ssh gave you.
        The result will be that your X app will try to run on the machine that you ssh'd to instead of the machine that you ssh'd from.
        Usually not what you want.

        non-Perl: Andy Ford

Re: Tk OSX couldn't connect to display :0
by Anonymous Monk on Aug 22, 2015 at 23:21 UTC
    Afte some struggle with my PTKDB perl debugger. Here is how I fix it. Get the latest download from the PERL/PTKDB team: Best luck to you!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://586134]
Approved by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-02-19 15:07 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (266 votes). Check out past polls.