运行时未知问题 Perl/Tk

Unknown issue in runtime Perl/Tk

我试过 SU 的这段代码,但它给出了这个错误:

couldn't connect to display ":0" at /usr/lib/perl5/vendor_perl/5.30/x86_64-cygwin-threads/Tk/MainWindow.pm line 53.
MainWindow->new() at A2.pl line 9.

我正在使用 Windows 8.

#!/usr/bin/perl
use warnings;
use strict;

use Tk qw{ MainLoop };

my $mw = 'MainWindow'->new;
my $b_show;
$b_show = $mw->Button(-text    => 'Show',
                      -command => sub {
                          $b_show->configure(-command => undef);
                          $mw->Button(-text    => 'Quit',
                                      -command => sub { exit })->pack;
                      })->pack;
MainLoop();

然后根据 answer and according to the Cygwin/X documentation, you need to install a Cygwin package called xinit打开一个新的Cygwin终端window并执行命令startxwin。然后在另一个 Cygwin 终端中,尝试重新运行您的脚本。这适用于 Windows 11.