gpt4 book ai didi

Python Tkinter canvas.xview 单位

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:16 26 4
gpt4 key购买 nike

Tkinter Canvas 滚动方法 xview(SCROLL, step, what)yview(SCROLL, step,什么) 定义?它是以像素为单位定义的吗?是否可以更改它(例如,为了更慢的滚动)?

要获得更好的上下文,请参阅代码 here .

提前致谢。

最佳答案

对于较慢的滚动,您可以使用 Canvas 的 xscrollincrement 和 yscrollincrement 选项:

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()

关于Python Tkinter canvas.xview 单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6863921/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com