The bad news is that the Optionmenu widget does not allow for cascades or any other 'fancy' menu behaviors.
The good news is that it shouldn't be too hard to extend it to get the behavior you want.
For a project, I needed to make an Optionmenu widget that could include separator items--also not possible with a basic Optionmenu. The answer was to subclass the Optionmenu widget and override the normal addOptions method.
sub addOptions { my $w = shift; my $menu = $w->menu; my $tvar = $w->cget(-textvariable); my $vvar = $w->cget(-variable); my $oldt = $$tvar; my $width = $w->cget('-width'); my %hash; my $first; while (@_) { my $val = shift; my $label = $val; if (ref $val) { if ($vvar == $tvar) { my $new = $label; $w->configure(-textvariable => ($tvar = \$new)); } ($label, $val) = @$val; } my $len = length($label); $width = $len if (!defined($width) || $len > $width); # This is the only bit that's different ===== if ( $label eq '-') { $menu->separator(); } else { # This was copied from the original method. $menu->command(-label => $label, -command => [ $w , 'setOption' +, $label, $val ]); } # END OF CHANGES ============================ $hash{$label} = $val; $first = $label unless defined $first; } if (!defined($oldt) || !exists($hash{$oldt})) { $w->setOption($first, $hash{$first}) if defined $first; } $w->configure('-width' => $width); }
TGI says moo
In reply to Re: Tk: cascade widget != menu
by TGI
in thread Tk: cascade widget != menu
by yike
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |