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

Hello all,

I am trying to create a Tk application. I am trying to use an Optionmenu widget by invoking it under Scrolled because this particular widget has a lot of items in it (using it as the days field in a date). When I do this, I just get a plain old Optionmenu. Does option menu not accept scrollbars? In case it matters, here is the appropriate code.

my $day_menu = $date_frame->Scrolled("Optionmenu",-scrollbars => "e", -textvariable => \$day, -variable => \$day_number, -options => [(1..$days{$month})] )->pack(-side => "left", );

Any insight that could be offered would be appreciated.

Thanks.

Replies are listed 'Best First'.
Re: Tk Optionmenu question
by Chmrr (Vicar) on Jan 28, 2002 at 11:28 UTC

    Your problem lies in that you don't want the Optionmenu itself scrolled -- you want the drop-down which it shows to be scrolled. Unfortunatly, what Tk thinks you're trying to do is the former. It's also not in your favor that Optionmenus drop down Menus -- which, if I'm remembering correctly, can't be scrolled in the first place.

    Luckily, you're not the first person to want to have a large pop-up list. Look at the BrowseEntry widget, which is automatically scrolled.

    Update: Here's some code which should do more of less what you want:

    my $day_menu = $date_frame->BroseEntry( -state => "readonly", -choices => [(1..$days{$month} +)], -variable => \$day_number )->pack( -side=> "left" );

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

      This is fantastic! Now all I have to do is find a way to alter the width of the box as it sits in the main window and I'll be golden.

      Thanks again

        One solution is to add -width => 42 in the code for creating the BrowseEntry. The other option is to diddle with the arguments to pack, specifically the -expand and -grow options.

        perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: Tk Optionmenu question
by thor (Priest) on Jan 28, 2002 at 10:49 UTC
    Oops. Forgot to log in before I posted this question. It is mine.

    thor