Discussion:
How to bind mouse wheel on Win32 Tk?
(too old to reply)
$Bill
2018-10-02 00:02:13 UTC
Permalink
Given a frame with a Listbox in it, I can't figure out how to bind
the mouse wheel to scroll the Listbox.

$lf1 = $mw->Labelframe(...
$lb1 = $lf1->Scrolled('Listbox',

I've tried using Widget.pm's YscrollBind, YMouseWheelBind, MouseWheelBind,
and even manually adding an event and binding it to yview/scroll.

Can someone insert a couple of lines of code below that works to bind
the mouse wheel on Win32 to scroll the Listbox content vertically ?

TIA, Bill

Test template:

#!perl --

use strict;
use warnings;
use Tk;

my $mw = new MainWindow (-title => "Test ($$)");

my $lf1 = $mw->Labelframe(-text => 'Test MW Bind',
-relief => 'ridge')->pack(-fill => 'both', -expand => 1
);

my $lb1 = $lf1->Scrolled('Listbox', -scrollbars => 'ose',
-width => 40, -height => 4, -selectmode => 'extended')->pack(
-side => 'bottom', -fill => 'both', -expand => 1
);


# bind y scroll to mouse wheel here



# fill with some data for testing
$lb1->insert('end', 'Testing 1234567890 Testing 1234567890') for (1 .. 20);

MainLoop ();


__END__
$Bill
2018-10-02 23:47:12 UTC
Permalink
Post by $Bill
Given a frame with a Listbox in it, I can't figure out how to bind
the mouse wheel to scroll the Listbox.
Turns out (with a lot of digging and some luck) that it's already
bound, but you have to hit the tab key to get it to focus on the
Listbox to get it to work.

Loading...