Mouse wheel event for Canvas
jmcmonagle at velseis.com.au
Fri Jun 23 02:08:14 CEST 2006
On Thu, 2006-06-22 at 14:24 +1000, John McMonagle wrote:
> I tried binding mouse wheel events (<Button-4>, <Button-5>) to a Tkinter
> Canvas widget with the hope of using the event.delta value to
> subsequently scroll the Canvas.
> However, it seems that event.delta always returns 0.
> For example,
> from Tkinter import *
> r = Tk()
> c = Canvas(r, scrollregion=(0,0,500,500), height=200, width=200)
> s = Scrollbar(r, command=c.yview)
> s.pack(side=RIGHT, fill=Y)
> def rollWheel(event):
> print event.delta
> c.bind('<Button-4>', rollWheel)
> c.bind('<Button-5>', rollWheel)
> Has anyone successfully managed to wheel scroll a Tkinter Canvas
> widget ?
I worked it out.
c.bind('<Button-4>', lambda event: event.widget.yview_scroll(-1, UNITS))
c.bind('<Button-5>', lambda event: event.widget.yview_scroll(1, UNITS))
I also changed the yscrollincrement to '5p'. The default moved a bit
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Python-list