Python Tkinter canvas.xview 单位

发布于 2024-11-27 02:56:10 字数 328 浏览 1 评论 0原文

Tkinter 画布滚动方法 xview(SCROLL,step,what)yview(SCROLL,step,what)< 中的“单位”(what)如何< /代码>定义?它是以像素为单位定义的吗?是否可以更改它(例如,滚动速度较慢)?

要获得更好的上下文,请参阅此处的代码

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_失温 2024-12-04 02:56:10

对于较慢的滚动,您可以使用 xscrollincrement & Canvas 的 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()

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()
无语# 2024-12-04 02:56:10

查看 -xview/-yview 选项的文档,尤其是 yscrollincrement 选项。所以是的,您可以更改步长。

-yscrollincrement

以屏幕距离允许的任何常用形式指定垂直滚动的增量。如果该选项的值大于零,窗口中的垂直视图将受到约束,使得窗口上边缘的画布 y 坐标始终为 yScrollIncrement 的偶数倍;此外,滚动的单位(例如,选择滚动条的顶部和底部箭头时视图的变化)也将为 yScrollIncrement。如果此选项的值小于或等于零,则垂直滚动不受限制。

yview滚动数是什么

此命令根据数字和内容向上或向下调整窗口中的视图。数字必须是整数。必须是单位或页。如果什么是单位,则视图以 yScrollIncrement 选项的单位向上或向下调整(如果它大于零),否则以窗口高度的十分之一为单位。如果是页面,则视图以窗口高度的十分之九为单位进行调整。如果数字为负数,则更高的信息变得可见;如果它是积极的,那么较低的信息就会变得可见。

来自 canvas 的 Tk 手册页。

Have a look at the docs for the -xview/-yview options, especially at the the yscrollincrement option too. So yes, you can change the step size.

-yscrollincrement

Specifies an increment for vertical scrolling, in any of the usual forms permitted for screen distances. If the value of this option is greater than zero, the vertical view in the window will be constrained so that the canvas y coordinate at the top edge of the window is always an even multiple of yScrollIncrement; furthermore, the units for scrolling (e.g., the change in view when the top and bottom arrows of a scrollbar are selected) will also be yScrollIncrement. If the value of this option is less than or equal to zero, then vertical scrolling is unconstrained.

and

yview scroll number what

This command adjusts the view in the window up or down according to number and what. Number must be an integer. What must be either units or pages. If what is units, the view adjusts up or down in units of the yScrollIncrement option, if it is greater than zero, or in units of one-tenth the window's height otherwise. If what is pages then the view adjusts in units of nine-tenths the window's height. If number is negative then higher information becomes visible; if it is positive then lower information becomes visible.

from the Tk manpage for canvas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文