in reply to Multi column option menu
If I were you, I would switch to a Tk::Canvas. The canvas would be a single widget, and it can handle many items ( canvas widgets) with more control too, such as various enter-leave-focus bindings which you can do with the canvas. The canvas also has a "tags" method, with which you can do many tricks with the items, like raise or lower them, etc. For instance, see Tk Virtual Keyboard
If you wish to stick with the option_menu method, I suggest just having only 1 option_method widget, and change the options as needed for each invocation. Here is a simple example of how to change options.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my @opt1 = ('a'..'m'); my @opt2 = ('n'.. 'z'); my $var = 'a'; my $tvar = 'a'; my $opt = $mw->Optionmenu( -command => \&show_choice, -variable => \$var, -textvariable => \$tvar, -options => \@opt1, )->pack; $mw->Button(-text=>'Change Options',-command=>[\&change_ops, $opt])->p +ack; $mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack; MainLoop; sub show_choice { print "got: ", shift, "\n" } sub change_ops { my $op = shift; $tvar = 'n'; $op->configure( -options => \@opt2 ); }
|
|---|