thegoaltender has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am just learning Tk. I am trying to change the items in a Menubutton when the choice of a set of Radiobuttons changes. The code currently will add items to the Menubutton, but I need to remove all items and then add the new items. Thanks for your help! Here is a subset of the code:
#widgets in Card $fastcard = $card->Radiobutton( -text=>"Fast Card", -value=>"fast", -variable=>\$cardspeed, -command=>\&card_choice )->pack(); $slowcard = $card->Radiobutton( -text=>"Slow Card", -value=>"slow", -variable=>\$cardspeed, -command=>\&card_choice )->pack();
...
#widgets in Card Usage $cardusagemenu = $cardusage->Menubutton( -textvariable=>\$cardusagechoice, -relief=>"raised", -borderwidth=>3 )->pack();
...
sub card_choice { if ($cardspeed eq "fast") { $cardusagemenu->AddItems([ "radiobutton"=>"1M Sample Full Channel 600MHz Conve +ntional", "-value"=>"1M Sample Full Channel 600MHz Convention +al", "-variable"=>\$cardusagechoice ], [ "radiobutton"=>"2M Sample Half Channel 1.2GHz Conve +ntional", "-value"=>"2M Sample Half Channel 1.2GHz Convention +al", "-variable"=>\$cardusagechoice ], [ "radiobutton"=>"1M Sample Full Channel 600MHz Trans +itional", "-value"=>"1M Sample Full Channel 600MHz Transition +al", "-variable"=>\$cardusagechoice ]); } elsif ($cardspeed eq "slow") { $cardusagemenu->AddItems([ "radiobutton"=>"2M Sample Full Channel 333MHz Conve +ntional", "-value"=>"2M Sample Full Channel 333MHz Convention +al", "-variable"=>\$cardusagechoice ], [ "radiobutton"=>"4M Sample Half Channel 666MHz Conve +ntional", "-value"=>"4M Sample Half Channel 666MHz Convention +al", "-variable"=>\$cardusagechoice ], [ "radiobutton"=>"2M Sample Full Channel 333MHz Trans +itional", "-value"=>"2M Sample Full Channel 333MHz Transition +al", "-variable"=>\$cardusagechoice ]); } }

Replies are listed 'Best First'.
Re: Changing Tk Menubutton Items
by b4e (Sexton) on Jul 29, 2004 at 20:07 UTC