Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk Optionmenu

Status
Not open for further replies.

zackiv31

Programmer
Joined
May 25, 2006
Messages
148
Location
US
After putting in all the options, is there any way to put a specific element of the options as the one that is selected. For me I want to put in the @array[1,2,3] and have the default choice be 3.. It seems to be random.
 
Add a value to the -variable option

The following example sets "red4" as the default value even though "Black" is first in the array list.

use Tk;
my $mw = MainWindow->new;
my $palette = 'red4';
my @colors = qw/Black red4 DarkGreen NavyBlue gray75 Red Green Blue
gray50 Yellow Cyan Magenta White Brown DarkSeaGreen DarkViolet/;

my $om = $mw->Optionmenu(
-variable => \$palette,
-options => [@colors],
-command => [sub {print "args=@_.\n"}, 'First'],
);
$om->pack;
MainLoop;
 
Not working for me...

I have @nodes = qw/n1 n2/;
my $variable = "n" . scalar(@nodes) #= n2;
$om -> configure(-variable => \$variable, -options = [@nodes]);

When I run this bit of code, it still selects n1..
 
When you use the $om->configure command, you have to use

-textvariable instead of -variable

Hth,
Raklet
 
Ahhh... great! Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top