in reply to How to Scroll multiple Frames using Tk::Pane

For your first post, you chose a whopper of a question....how to link nested scrolled widgets.

First use warnings and use strict.

Second this is kind of complex to answer, because Scrolled widgets do some internal magical linking, so trying to orchestrate them all together, and still allow them to work independently, is intricate.(More than I care to sweat over this afternoon :-)) You may be better off building ALL your widgets with manual scrollbars, then somehow juggling everything.

But here is a start with a ScrolledPane. The only glitch is that the master scrollbar only works when you hit the up or down arrow graphics (which move things 1 unit in that direction). If you try to drag the green bar, everything resets to the master yview.

If it was me, I would ditch the master scrollbar,and make custom labels with up/down arrows to replace the master scrollbar, and just have them do a + or - 1 unit increment, instead of the yview(@_). In other words, use a Pane, instead of the ScrolledPane, and pack a frame on the left, with an up and down label. Link each label's mouse 1 click to scroll 1 unit in all Scrolled Listboxes.

But if you are persistent and clever, you may be able to setup a yscrollcommand that dosn't reset all listboxes to the @_ of the yscrollbar, but it's up to you, or someone else may know the trick.

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new(); $mw->geometry("600x300+100+100"); $mw->Button( -text => "Exit", -command => sub { exit } )->pack( -side => 'bottom', -fill => 'x' ); my $parent = $mw->Scrolled('Pane' ) ->pack( -fill => 'both', -expand => 1 ); my $yscroll = $parent->Subwidget('yscrollbar'); my @listboxes; foreach my $num (1..4) { my $list = $parent->Scrolled('Listbox'); foreach my $num (1..100){ $list->insert( 'end', $num); } $list->pack( -side => 'left', -fill => 'y', -expand => 1 ); push @listboxes, $list; } $yscroll->configure( -background => "lightgreen", -troughcolor => "black", -command => sub { foreach my $list (@listboxes) { $list->yview(@_); # $list->yviewScroll(1,'units'); } }, ); MainLoop;

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

Replies are listed 'Best First'.
Re^2: How to Scroll multiple Frames using Tk::Pane
by ravishi (Acolyte) on Sep 10, 2008 at 19:47 UTC
    Ok, thanks for the help guys! I now understand how to have the scrollbar scroll multiple frames at the same time. But, now I would like to know how to get the scrollbar to talk with the frames to have the scrollbar actually represent where it is in the frames. Also, I'd like for it to not reset the starting position at the beginning every time you click on the slider. I'm not sure if this is possible with regards to what zentara said.