How are the 'units' (what) from the Tkinter canvas scrolling methods xview(SCROLL, step, what) and yview(SCROLL, step, what) defined? Is it defined in pixels? Is it possible to change it (for a slower scrolling for example)?
For a better context please see the code here.
Thanks in advance.
for slower scrolling, you can play around with the xscrollincrement & yscrollincrement options of the Canvas:
from Tkinter import *
root = Tk()
c = Canvas(root, scrollregion=(0,0,500,500), height=200, width=200)
s = Scrollbar(root, command=c.yview)
c.pack(side=LEFT)
s.pack(side=RIGHT, fill=Y)
c.configure(yscrollcommand=s.set)
c.configure(yscrollincrement='2')
##yscrollincrement - increment for vertical scrolling, in pixels,
##millimeters '2m', centimeters '2c', or inches '2i'
c.create_rectangle(10,10,100,100)
c.create_rectangle(10,200,100,300)
def rollWheel(event):
direction = 0
if event.num == 5 or event.delta == -120:
direction = 1
if event.num == 4 or event.delta == 120:
direction = -1
event.widget.yview_scroll(direction, UNITS)
c.bind('<MouseWheel>', lambda event: rollWheel(event))
c.bind('<Button-4>', lambda event: rollWheel(event))
c.bind('<Button-5>', lambda event: rollWheel(event))
c.focus_set()
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With