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

#!/usr/local/bin/perl use Tk; my $bufferid=0; my $mw = new MainWindow; my $scl_bufferid = $mw ->Optionmenu(-options => [0,1,2,3,4,5,6,7,8,9,1 +0,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,3 +3,34,35,36,37,38,39,40,41],-variable => \$bufferid); $scl_bufferid-> grid(-row=>1,-column=>1); MainLoop;
Say, I am using this script. The GUI displays all the nos. from 0 to 41 in a stroke, but at a time I want to display 10 options with scroll bar to right, to explore the remaining options. Main thing is I dont want to display the long 41 nos. list at a time, and still want to make all 41 options accessible!Please reply as soon as possible! Thanks!

Replies are listed 'Best First'.
Re: PERL/TK Optionmenu problem
by Anonymous Monk on Nov 27, 2008 at 08:55 UTC
Re: PERL/TK Optionmenu problem
by zentara (Cardinal) on Nov 27, 2008 at 13:34 UTC
    One way to do it, would be to have listboxes taking the output of the optionmenu.
    #!/usr/bin/perl use warnings; use strict; use Tk; my @fruits = ("apple","pear","orange","starfruit","pineapple"); my @veggies = ("tomato","chard","spinach","beans","radish"); my @treats = ("chocolate","icecream","raspberries","pretzels","chips") +; my %hash = ( fruits=> \@fruits, veggies => \@veggies, treats=> \@treats); my @sel = keys %hash; my $mw = MainWindow->new(); my $choice = 'apple'; my $selection = ''; my $bframe1= $mw->Frame()->pack(-side => "bottom"); my $bframe= $mw->Frame()->pack(-side => "bottom"); my $list = $bframe->Scrolled('Listbox', -listvariable => \@sel, -scrollbars=>'osoe', )->pack(-side=>'left'); my $list1 = $bframe->Scrolled('Listbox', # -listvariable => \@sel, -scrollbars=>'osoe', )->pack(-side=>'right'); my $om = $mw->Optionmenu( -options=> \@sel, -textvariable=>\$choice, -width=>'25', -command => sub{ @sel = @{$hash{$choice}} }, )->pack(-expand => '1'); $list->bind( '<ButtonRelease-1>', sub { update( $_[0], $list1 ) } ); $list1->bind( '<ButtonRelease-1>', sub { $selection = $_[0]->get( $_[0]->curselection ); # print "$sel\n"; } ); my $sel_label = $bframe1->Label( -textvariable => \$selection)->pack(); MainLoop; sub update { my ( $src, $dst ) = @_; my $index = $src->curselection; if ($index) { $dst->delete( 0, 'end' ); my $value = $src->get($index); foreach my $type(1..100){ $dst->insert( 'end', $value.$type ); } } }

    I'm not really a human, but I play one on earth Remember How Lucky You Are