2013-09-30 27 views
1

如果可能,我需要通過將數組綁定到選項菜單來自動更新Perl Tk中的選項菜單。將選項菜單綁定到Perl中的數組TK

舉個例子,我可以用一個列表框成功地做到這一點:

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

然而,當我嘗試做同樣的一個Optionmenu它無法自動加載。

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

這不可能嗎?或者我做錯了什麼?謝謝。

+0

領帶接口不是'Tk的:: Optionmenu'實現。但我接受補丁:-) –

回答

0

在回顧了模塊之後,我發現了一個解決方案,儘管時間更長 - 仍然是一個解決方案。我希望這能幫助那些與這些老東西合作的人。

這裏是模塊:http://cpansearch.perl.org/src/SREZIC/Tk-804.031/Tk/Optionmenu.pm

添加一個選項optionmenu

# 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]); 
相關問題