例如在以下脚本中:
use Tk;
my $mw = new MainWindow;
my $t = $mw->Scrolled("Text")->pack;
my $popup = $mw->Menu(
-menuitems => [
[
Button => 'Copy Selected',
-state => "disabled",
-command => sub {$t->clipboardColumnCopy}
],
]
);
$t->menu($popup);
MainLoop;
如何判断选择何时发生,以便我可以使用以下代码
$popup->entryconfigure(1, -state=>'normal');
改变菜单项状态?
更新:
非常感谢@Chas 和@gbacon :)
我想也许我也可以将两个好的答案结合起来:
$t->bind(
"<Button1-ButtonRelease>",
sub {
local $@;
my $state = defined eval { $t->SelectionGet } ?
"normal" : "disable";
$popup->entryconfigure(1, -state => $state)
}
);