0
我正在使用Tkx模塊創建一個填充了@list文本值的窗口。然後我用一個checkbutton選擇一個或多個。我想在按下'OK'按鈕後打印已經選擇的按鈕,但不知道如何將變量傳遞給'OK'-command => sub {}。謝謝。如何使用Tkx中的checkbutton打印選定的值
use autodie;
use strict;
use warnings;
use Tkx;
my $mw = Tkx::widget->new(".");
$mw->g_wm_title("Listbox");
$mw->m_configure(-background => "#191919");
my $width = '700';
my $height = '500';
Tkx::update('idletasks');
$width ||= Tkx::winfo('reqwidth', $mw);
$height ||= Tkx::winfo('reqheight', $mw);
my $x = int((Tkx::winfo('screenwidth', $mw)/2) - ($width/2));
my $y = int((Tkx::winfo('screenheight', $mw)/2) - ($height/2));
$mw->g_wm_geometry($width . "x" . $height . "+" . $x . "+" . $y);
my @list = ('TEXT1', 'TEXT2', 'TEXT3', 'TEXT4', 'TEXT5');
for my $list (@list) {
my $cb = $mw->new_ttk__checkbutton(
-text => $list,
-onvalue => 1,
-offvalue => 0,
);
$cb->g_pack(
-anchor=>'w',
-side=>'top',
-fill => 'x'
);
}
my $ok = $mw->new_button(
-text => "OK",
-command => sub {
print "Selected Values";
Tkx::after(500, sub { $mw->g_destroy });
},
);
$ok->g_pack(
-anchor=>'c',
-side=>'bottom',
);
Tkx::MainLoop();
是。這正是我想要的。非常感謝解決方案。 – thebourneid