【问题标题】:Tie an Optionmenu to an array in Perl TK在 Perl TK 中将 Optionmenu 绑定到数组
【发布时间】:2013-09-30 17:25:07
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

  • Tk::Optionmenu 没有实现绑定接口。但我接受补丁 :-)

标签: perl tk perltk


【解决方案1】:

在查看模块后,我注意到了一个解决方案,虽然更长——仍然是一个解决方案。我希望这可以帮助那里的人处理这些旧东西。

这里是模块: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]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多