将选项菜单绑定到 Perl TK 中的数组



如果可能的话,我需要通过将数组绑定到 Optionmenu 来自动更新 Perl Tk 中的选项菜单。

举个例子,我可以用列表框成功地做到这一点:

tie @datafile, "Tk::Listbox", $lb;

但是,当我尝试对选项菜单执行相同的操作时,它无法自动加载。

tie @optionfile, "Tk::Optionmenu", $om;

这不可能吗?还是我做错了什么?谢谢。

在查看模块后,我注意到了一个解决方案,尽管时间更长 - 仍然是一个解决方案。我希望这有助于有人在那里处理这些旧东西。

这是模块:http://cpansearch.perl.org/src/SREZIC/Tk-804.031/Tk/Optionmenu.pm

向选项菜单添加选项

# Add to the array 
push @datafile3, $newReport;
# Add to the optionmenu
$om->addOptions($newReport);

然后删除

# removing an option from the array and also the optionmenu itself. 
my $index = 0;
# remove from array
$index++ until $datafile3[$index] eq $selectBatch;
splice(@datafile3, $index, 1);
# remove from menu
$om->configure( -options  => [@datafile3]);

最新更新