Nochmal zur Verdeutlichung:
Hier scrollt der Canvas immer mit:
use Tk;
my $top = new MainWindow;
$top->Scrolled("Listbox")->pack->insert("end", keys %ENV);
$top->Scrolled("Listbox")->pack->insert("end", keys %INC);
my $c = $top->Scrolled( qw/Canvas
-width 400 -height 400 -relief sunken
-bg white -borderwidth 1 -scrollbars se -scrollregion/ =>
[qw/0 0 1000 1000/])->pack;
$top->bind($top, '<MouseWheel>',
[sub { my $unit = $_[1] > 0 ? -1 : 1;
$c->yviewScroll($unit => 'units')
},
Ev('D')]
);
MainLoop;
Hier scrollt er nur wenn er den focus hat:
use Tk;
my $top = new MainWindow;
$top->Scrolled("Listbox")->pack->insert("end", keys %ENV);
$top->Scrolled("Listbox")->pack->insert("end", keys %INC);
my $c = $top->Scrolled( qw/Canvas
-width 400 -height 400 -relief sunken
-bg white -borderwidth 1 -scrollbars se -scrollregion/ =>
[qw/0 0 1000 1000/])->pack;
my $ic = $c->Subwidget('scrolled');
$top->MouseWheelBind($ic);
MainLoop;