错误无法连接到显示":0"在/usr/lib/perl5/vendor_perl/5.22/x86_64-cygwin-threads/Tk/MainWindow.pm第53行。 MainWindow-> new()at ./PerlUI.pl第6行。
代码是:
#!/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;
答案 0 :(得分:2)
您需要先X
开始。
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.
通过调用X
启动X,这将打开一个新窗口,然后运行您的脚本。
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