Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter canvas.xview units

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.

like image 862
Marcos Saito Avatar asked Aug 27 '26 11:08

Marcos Saito


1 Answers

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()
like image 125
noob oddy Avatar answered Aug 29 '26 01:08

noob oddy