If you want to control the bindings of your scrollbars manually, it is a PITA full of details. Here is a decent example
However, if you don't need the same scrollbar linking multiple widgets, you usually just use a scrolled Pane, and add frames to the scrolled Pane, then addwhatever you want to the Frames. Like:
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Pane;
my $mw = tkinit;
my $spane = $mw->Scrolled('Pane',
-scrollbars => 'osoe',
-bg => 'blue',
)->pack(-expand => 1, -fill => 'both');
# create 2 frames side by side in the pane, and fill with more frames
my $lframe = $spane->Frame(-bg=>'red')->pack(-side=>'left',-padx=>3);
my $rframe = $spane->Frame(-bg=>'red')->pack(-side=>'right',-padx=>3);
my %frames;
for(1..100){
$frames{$_}{'frame'} = $lframe->Frame()->pack(-pady => 5 );
$frames{$_}{'label'} = $frames{$_}{'frame'}->Label(-text=>'Frame '.$
+_)->pack;
my $num = $_;
$frames{$_}{'button'} = $frames{$_}{'frame'}->Button(
-text=>'Button '.$_,
-command => sub{print "$num pressed\n"},
)->pack;
}
for(101..200){
$frames{$_}{'frame'} = $rframe->Frame()->pack(-pady => 5 );
$frames{$_}{'label'} = $frames{$_}{'frame'}->Label(-text=>'Frame '.$
+_)->pack;
my $num = $_;
$frames{$_}{'button'} = $frames{$_}{'frame'}->Button(
-text=>'Button '.$_,
-command => sub{print "$num pressed\n"},
)->pack;
}
MainLoop;
|