problme when trying to use mouse wheel for scrolling in a canvas

"Henry Merryweather" <[email protected]>
Newsgroups gmane.comp.lang.perl.tk
Message-ID <009301c59c3a$08070080$0200a8c0@eveshampc>
I would like to use the central mouse wheel to scroll on a canvas.  I am
running under windows (XP).  Attached is some test code.
 
 
use Tk;
 
use strict "vars";
 
my ($mw_Main, $canvas, $real_canvas);
 
# sub to add centre wheel of mouse for scrolling
 
sub BindMouseWheel {
 
    my($w) = @_;
 
    if ($^O eq 'MSWin32') {
        $w->CanvasBind('<MouseWheel>' =>
            [ sub { $_[0]->yview('scroll', -($_[1] / 120) * 3, 'units')
},
                Ev('D') ]
        );
    } else {
 
# other o/s code was here
 
    }
}
 
 
$mw_Main = MainWindow->new;
 
$canvas = $mw_Main->Scrolled("Canvas",
                                                -width                =>
300,
                                                -height              =>
300,
                                                -xscrollincrement => 5,
                                                -yscrollincrement => 5,
                                                -scrollregion       =>
[0,0,500,500],
                                    )->pack();
 
$real_canvas = $canvas->Subwidget("canvas");
 
$real_canvas->createLine(0,0, 499, 499);
$real_canvas->createLine(0, 499, 499, 0);
 
BindMouseWheel($real_canvas);
 
 
MainLoop;
 
 
The test code creates a scrolled canvas area and draws a diagonal cross
between the corners.
 
It then calls the sub BindMouseWheel which is exactly as in Mastering
Perl/Tk except that bind has been changed to CanvasBind.
 
Sadly nothing happens when I use the mouse wheel - I had hoped that the
picture (cross) in the canvas would scroll up and down.
 
Is it possible to use the mouse wheel to scroll in a canvas?  If so
could someone:
1.	explain how to amend the test code so that this works;
2.	give the Perl code so that (if possible) the mouse wheel (that
can be moved from side to side and does give a horizontal scroll in
other applications) can be used to scroll in the x direction as well.
 
Best regards
 
Henry Merryweather
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.