Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Tk Optionmenu - how to set the default selection

by Minok (Novice)
on Feb 10, 2009 at 18:29 UTC ( #742846=note: print w/replies, xml ) Need Help??


in reply to Re: Tk Optionmenu - how to set the default selection
in thread Tk Optionmenu - how to set the default selection

Well, there-in lies the solution. Just setting the attribute of -textvariable a second time fixed the issue.

Adding

$platformDropdown -> configure( -textvariable => \$platformChoice );
to the end does the trick.... which pokes the TK engine and says "Hey, set the value to THIS". Even though the variable already contained the right value, I guess TK needs to have some sort of event to know it needs to update. So the corrected code, that now works, looks like:
my %solutionMatrix; my $defaultPlatform = "Mod1"; $solutionMatrix{"Mod1"} = [ 'a','b','c' ]; $solutionMatrix{"Mod2"} = [ 'q' ]; my $platformDropdown = $selectionFrame -> Optionmenu ( -textvariab +le => \$platformChoice, -indicatoron => 1 ) -> pack( -side => "left") +; # --- now populate the options in the platform and customer dr +opdown list, # which is in the hash of arrays, %solutionMatrix foreach my $platform ( sort keys %solutionMatrix ) { # $platform is a choice for the platform dropdown # @{$solutionMatrix{$platform} is an array of solutions fo +r the customer dropdown $platformDropdown -> addOptions([$platform=>$platform]); } $platformChoice = $defaultPlatform; # set default $platformDropdown -> configure( -textvariable => \$platformCho +ice );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://742846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2020-07-04 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?