Home > Archive > PerlTk > October 2005 > Optionmenu drop-down width
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Optionmenu drop-down width
|
|
| woodenbicycle@hotmail.com 2005-10-07, 6:58 pm |
| With Optionmenu I am able to specify a -width so that all of buttons
are about the same size. But this has no effect on how wide the actual
drop-down menu is. The drop-down menu seems to be only as wide as the
widest option. Is there any way I can force the drop-down menu to be as
wide as the button itself (without padding the entry with spaces)? It
is a bit of a pain to click on a wide Optionmenu button, then have to
drop down and move the cursor to the left as well. I would like to
click and move straight down, I would like a larger click target area.
This is especially annoying for drop down Optionmenus containing only
single digit numbers.
| |
| Jack D 2005-10-07, 6:58 pm |
| <woodenbicycle@hotmail.com> wrote in message
news:1128699276.852796.54810@g47g2000cwa.googlegroups.com...
> With Optionmenu I am able to specify a -width so that all of buttons
> are about the same size. But this has no effect on how wide the actual
> drop-down menu is. The drop-down menu seems to be only as wide as the
> widest option. Is there any way I can force the drop-down menu to be as
> wide as the button itself (without padding the entry with spaces)? It
> is a bit of a pain to click on a wide Optionmenu button, then have to
> drop down and move the cursor to the left as well. I would like to
> click and move straight down, I would like a larger click target area.
> This is especially annoying for drop down Optionmenus containing only
> single digit numbers.
>
You should seriously consider using BrowseEntry or JComboBox instead.
The easiest way to ensure not having to move your cursor left or right - is
to set the -direction option. (Optionmenu is a derived Menubutton - so all
methods are inherited). It won't increase the width of your menu but it
allows easy up/down access to the thinner menu.
use Tk;
use Tk::Optionmenu;
use strict;
my $mw=tkinit;
my $om=$mw->Optionmenu(
-direction=>'flush',-width=>60,
-options=>[qw/1 2 3 4 5/],
)->pack;
MainLoop;
__END__
Here is a real *ugly* hack which basically inserts a blank bitmap into the
menu in order to increase it's size. Not suggested for your code - but - it
shows that workarounds can almost always be found. :-)
use Tk;
use Tk::Optionmenu;
use strict;
my $mw=tkinit;
my $om=$mw->Optionmenu(
-width=>60,
-options=>[qw/1 2 3 4 5/],
)->pack;
my $width = $om->reqwidth;
my $diff = $width - 45; #close to default padding on win32
my $lbm = pack ("b$diff", '0' x $diff);
my $menu = $om->menu;
$menu->DefineBitmap('blank',$diff,1,$lbm);
$menu->add('command',-bitmap=>'blank',-state=>'disabled');
MainLoop;
__END__
#Jack
|
|
|
|
|