#!/usr/bin/perl # Multiple Widgets with one scrollbar.pl use Tk; require Tk::Pane; $mw = MainWindow->new(); $mw->title("One Scrollbar/Three Listboxes"); $mw->Button(-text => "Exit", -command => sub { exit })->pack(-side => 'bottom'); $scroll =$mw->Scrollbar(); # Anonymous array of the three Listboxes $listboxes = [ $mw->Scrolled(Pane, -scrollbars => 'ose', -sticky => 'nsew', -background => 'green') +, $mw->Scrolled(Pane, -scrollbars => 'ose', -sticky => 'nsew', -background => 'blue'), $mw->Scrolled(Pane, -scrollbars => 'ose', -sticky => 'nsew', -background => 'cyan') +]; # This method is called when on Listbox is scrolled with the keyboard # It makes the Scrollbar reflect the chang, and scrolls the other list +s sub scroll_listboxes { my ($sb, $scrolled, $lbs, @args) = @_; $sb->set(@args); # tell the Scrollbar what to display my ($top, $bottom) = $scrolled->yview(); foreach $list (@$lbs) { $list->yviewMoveto($top); # adjust each lb } } # Configure each Listbox to call &scroll_listboxes foreach $list (@$listboxes) { $list->configure(-yscrollcommand => [ \&scroll_listboxes, $scroll, $list, $listboxes ] ); } # Configure the Scrollbar to scroll each Listbox $scroll->configure(-command =>sub { foreach $list (@$listboxes) { $list->yview(@_); }}); # Pack the Scrollbar and Listboxes $index = 0; $scroll->pack(-side => 'left', -fill => 'y'); foreach $list (@$listboxes) { $list->pack(-side => 'left'); $list->Label(-text => "One")->pack(); $list->Label(-text => "Two")->pack(); $list->Label(-text => "Three")->pack(); $list->Label(-text => "Four")->pack(); $list->Label(-text => "Five")->pack(); $list->Label(-text => "Six")->pack(); $list->Label(-text => "Seven")->pack(); $list->Label(-text => "Eight")->pack(); $list->Button(-text => "$index", -command => sub { exit})->pac +k(); $index++; } MainLoop;
This is my first post so be easy on me. Thanks!Tk::Error: Can't call method "rooty" without a package or object reference at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Tk +/ Pane.pm line 256. Tk::Pane::yview at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread- multi/Tk/Pane.pm line 256 Tk::Derived::Delegate at /usr/lib/perl5/site_perl/5.8.8/i386-linux- thread-multi/Tk/Derived.pm line 469 Tk::Widget::__ANON__ at /usr/lib/perl5/site_perl/5.8.8/i386-linux- thread-multi/Tk/Widget.pm line 322 main::__ANON__ at ./multiScroll2.pl line 49 Tk::Scrollbar::ScrlByPages at ../blib/lib/Tk/Scrollbar.pm (autosplit into ../blib/lib/auto/Tk/Scrollbar/ScrlByPages.al) line 372 Tk::Scrollbar::Select at ../blib/lib/Tk/Scrollbar.pm (autosplit into ../blib/lib/auto/Tk/Scrollbar/Select.al) line 201 Tk::Scrollbar::ButtonDown at ../blib/lib/Tk/Scrollbar.pm (autosplit into ../blib/lib/auto/Tk/Scrollbar/ButtonDown.al) line 159 <Button-1> (command bound to event)
In reply to How to Scroll multiple Frames using Tk::Pane by ravishi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |