BrainsOfSteel BrainsOfSteel - 1 month ago 12
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/MainWindow.pm line 53.
MainWindow->new() at ./PerlUI.pl line 6.

The code is:

#!/usr/bin/perl -w

use strict;
use Tk;

my $mw=MainWindow->new;
$mw->geometry("200x100");
$mw->title("Hello World!!");
$mw->Label(-text=>"Hello World")->pack();
$mw->Button(-text=>"Close",-command=>sub{exit})->pack();
MainLoop;

Answer

You need to start X first.

perl hello_world_tk.pl
couldn't connect to display ":0" at /usr/lib/perl5/vendor_perl/5.22/i686-    cygwin-threads-64int/Tk/MainWindow.pm line 53.
MainWindow->new() at hello_world_tk.pl 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
Release: 1.18.4.0
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:

X

.... more X output

# Now run your script

perl hello_world_tk.pl

Hello World