我开始将 Perl Tk 用于我的 UI 设计。我在 perl 中创建了一个小代码并收到以下错误
I am starting to use Perl Tk for my UI design in. I created a small code in perl and got the following error
错误是无法连接到 /usr/lib/perl5/vendor_perl/5.22/x86_64-cygwin-threads/Tk/MainWindow.pm 第 53 行显示“:0”。
MainWindow->new() 在 ./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;
您需要先开始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,这将打开一个新的 window,然后 运行 您的脚本。
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
错误是无法连接到 /usr/lib/perl5/vendor_perl/5.22/x86_64-cygwin-threads/Tk/MainWindow.pm 第 53 行显示“:0”。 MainWindow->new() 在 ./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;
您需要先开始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,这将打开一个新的 window,然后 运行 您的脚本。
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