By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Mouse wheel event for Canvas

P: n/a
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)
c.pack(side=LEFT)
s.pack(side=RIGHT, fill=Y)
c.configure(yscrollcommand=s.set)
c.create_rectangle(10,10,100,100)
c.create_rectangle(10,200,100,300)

def rollWheel(event):
print event.delta

c.bind('<Button-4>', rollWheel)
c.bind('<Button-5>', rollWheel)

c.focus_set()

r.mainloop()
Has anyone successfully managed to wheel scroll a Tkinter Canvas
widget ?

Regards,

John

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Jun 22 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.