Tk mouse wheel events?

Steve Holden sholden at holdenweb.com
Thu Aug 15 13:45:04 EDT 2002


"Fredrik Lundh" <fredrik at pythonware.com> wrote ...
> Edward K. Ream wrote:
>
> > I am trying to get a binding to fire when the mouse wheel moves.
Vertical
> > scrolling is handled automatically by the Tk.Text widget, and I would
like
> > to scroll a canvas.  The canvas is in a toplevel that includes Text
widgets.
> >
> > From a Google search it appears that Button-4 and Button-5 events might
do
> > the job. I don't see this documented on the Tk man pages though.
> >
> > The following doesn't seem ever to call the event handlers, no matter
what
> > kind of widget is used:
> >
> > widget.bind("<Button-4>",self.OnButton4)
> > widget.bind("<Button-5>",self.OnButton5)
> >
> > Does anyone have any advice or example code?  Thanks!
>
> from Tkinter import *
>
> def roll(event):
>     print event.delta
>
> frame = Frame(width=200, height=200)
> frame.pack()
> frame.focus_set() # wheel events goes to focussed window
> frame.bind("<MouseWheel>", roll)
>
> mainloop()
>

Fredrik:

Did I ever say "thank you" for all your excellent work on Python? Tkinter,
regular expressions ... an amazing contribution!

[makes note to propose Fredrik for next year's ActiveState awards]. Thank
you!!!!

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list