Tk MouseWheel Support

Alexander Kapps alex.kapps at web.de
Thu Mar 10 15:56:52 EST 2011


On 10.03.2011 21:28, Richard Holmes wrote:
> I am trying to use the mouse wheel to scroll a list box, but I'm not
> getting the event. When I bind "<Button-1>" to the listbox I get the
> event and I'm able to scroll using yview_scroll. I've tried binding
> "MouseWheel" and"<MouseWheel>", and I've also tried"<Button-4>" and
> "<Button-5>" even though I'm using Windows (XP, if that makes a
> difference). None of these works (I'm using print to see if I got to
> an event handler, and there's no printout).
>
> TIA for any help!
>
> Dick

Can you post your code please (if it's too long, strip it down to 
the smallest program which still shows the problem.)

On Ubuntu 10.04, Python 2.6.5, the Listbox already recognizes the 
mouse wheel. Listbox aside, the following works here:


import Tkinter as tk

def wheel_up(event):
     print "wheel_up", event

def wheel_down(event):
     print "wheel_down", event

root = tk.Tk()
root.bind("<Button-4>", wheel_up)
root.bind("<Button-5>", wheel_down)
root.mainloop()



More information about the Python-list mailing list