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

I am short of space and I need to use a number of option menus.
To save space I want to remove the small ‘button’ type shape that is given to the right
of the ‘top’ item of the menu options.
I have used the Native Option menu (Mastering Perl/Tk page 277) as that has
more configuration choices.
I tried using the –hidemargin => 1 option but this only made the entries in the pull down list
more narrow and did not alter the top entry.
How can I remove the button shape at the top?
  • Comment on Tk - how to alter appearance of Option Menu

Replies are listed 'Best First'.
Re: Tk - how to alter appearance of Option Menu
by thundergnat (Deacon) on Jun 05, 2008 at 15:03 UTC

    Optionmenu is derived from Menubutton which has the -indicatoron option to show or hide that 'button'. Unfortunately, the author of Optionmenu decided to hardcode the state of -indicatoron to true in the Optionmenu Populate sub. That means you can not change the configuration as it is being constructed, (unless you build your own widget or override the Populate sub). You CAN however, easily change the state after it has been built.

    use warnings; use strict; use Tk; my $mw = MainWindow->new(); my ( $var, $tvar ); my $opt = $mw->Optionmenu( -options => [ [ jan => 1 ], [ feb => 2 ], [ mar => 3 ], [ apr => 4 ], [ may => 5 ], [ jun => 6 ], [ jul => 7 ], [ aug => 8 ] ], -command => sub { print "got: ", shift, "\n" }, -variable => \$var, -textvariable => \$tvar, )->pack; # Now reconfigure the indicator button $opt->configure( -indicatoron => 0 ); MainLoop;
      Many thanks - it works just as I wanted it too!
      I suspect I would never have found it without your help.