Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scroll Multiple Frames using Tk::Pane

10 views
Skip to first unread message

ravishi

unread,
Sep 9, 2008, 11:53:00 AM9/9/08
to
I have a program in which I am trying to create a scrollbar that can
scroll multiple frames. Each frame has its own scrollbar using
Tk::Pane. I have found code online which provides a solution if I was
using Listboxes but not for Frames. Below is my code:

#!/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
lists
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})->pack();
$index++;
}

MainLoop;


When I run it, it displays my three Frames with their own individual
scrollbars. But when I try to control the main scrollbar, it gives me
this error

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)

0 new messages