Perl/Tk under Mac OS X

Posted by jarlook on 2007-01-18 19:07

Trying to use Tk with Mac OS X.
Program fails on immediately:

couldn't connect to display ":0" at /usr/local/ActivePerl-5.8/lib/Tk/ line 55.
MainWindow->new() at tktest line 3

I see this referenced on the web, but no clear solution.
Anyone with the answer?

jeff.griffiths | Fri, 2007-01-19 08:34

Perl/Tk on MacOSX requires that you run X11 for Windowing support, as it does not support the native Windowing system. If you want a native Tk-based Gui toolkit, you should look at Tkx instead:

Tkx is based on Tcl/Tk and was developed by ActiveState for creating cross-platform Gui applications in Perl. We use it for the Gui interfaces in the PDK, as well as PPM 4.

JeffG | Komodo 4.0 Beta | MacBook Pro OS X Intel / Ubuntu 6.06 i386

jarlook | Sat, 2007-01-20 15:57

Thanks jeffg for the suggestion. I tried Tkx and it works as you advertised. It seems though that Tkx requires a very different set of calls than working directly with Tk, which I am currently trying to decipher.

I have programs that used Tk in a Windows environment and would thus still like to use Tk directly, and avoid rewriting. I do have X11 installed, so if anyone still knows how to get Tk working in a Mac OS X environment, I'm still interested.

ActiveState Staff
Tue, 2007-01-23 10:58

Can you describe what sort of error or problem you're running into when trying to run Perl/Tk scripts on OS X? I am able to do this without trouble.



jarlook | Tue, 2007-01-23 13:34

Even the most threadbare program doesn't work. As I noted in the original comment, I get the following error message:

couldn't connect to display ":0" at /usr/local/ActivePerl-5.8/lib/Tk/ line 55.

MainWindow->new() at tktest line 3


jeff.griffiths | Tue, 2007-01-23 15:31

You need to start X11, then call the perl script from the terminal in X11, otherwise there is no X11 server for Tk to connect to. Warning, though - X11 / Tk on OS X is pretty ugly cmpared to a native Gui.

JeffG | Komodo IDE 4.0 | MacBook Pro OS X Intel / Ubuntu 6.06 i386

veljkopopovic | Fri, 2009-02-27 01:11

..... to catch X server down in perl TK on mac os... when i hit commmand-Q on X11 instance i receive simple shutdown warning with no signal emitted at all.

Best regards....