BrainsOfSteel BrainsOfSteel - 10 months ago 41
Perl Question

I am starting to use Perl Tk for my UI design in. I created a small code in perl and got the following error

The error is couldn't connect to display ":0" at /usr/lib/perl5/vendor_perl/5.22/x86_64-cygwin-threads/Tk/ line 53.
MainWindow->new() at ./ line 6.

The code is:

#!/usr/bin/perl -w

use strict;
use Tk;

my $mw=MainWindow->new;
$mw->title("Hello World!!");
$mw->Label(-text=>"Hello World")->pack();

Answer Source

You need to start X first.

couldn't connect to display ":0" at /usr/lib/perl5/vendor_perl/5.22/i686-    cygwin-threads-64int/Tk/ line 53.
MainWindow->new() at line 6.

Start X by invoking X, which will open up a new window and then run your script.

X &

Vendor: The Cygwin/X Project
OS: CYGWIN_NT-6.1 EAPB8CA3AA75D7E 2.6.0(0.304/5/3) 2016-08-31 14:27 i686
OS: Windows 7 Service Pack 1 [Windows NT 6.1 build 7601] (Win32)
Package: version 1.18.4-1 built 2016-07-22

winInitializeScreenDefaults - primary monitor w 1280 h 1024
winInitializeScreenDefaults - native DPI x 96 y 96
XWin was started with the following command line:


.... more X output

# Now run your script


Hello World