【发布时间】:2021-02-09 17:02:34
【问题描述】:
我通过转到系统偏好设置/鼠标/滚动方向更改了我的 mac 上的鼠标滚动行为:自然 - 取消选择。但是我的 python 程序仍然使用自然滚动方向。我该如何扭转它?
from tkinter import *
# initialize position and size for root window
position_x = 100
position_y = 50
size_x = 625
size_y = 600
root = Tk()
root.title("Mouse Kung Fu version {}".format("3.008"))
root.geometry("%dx%d+%d+%d" % (size_x, size_y, position_x, position_y))
F = Frame(root)
F.pack(fill=BOTH, side=LEFT)
# link up the canvas and scrollbar
S = Scrollbar(F)
C = Canvas(F, width=1600)
S.pack(side=RIGHT, fill=BOTH)
C.pack(side=LEFT, fill=BOTH, pady=10, padx=10)
S.configure(command=C.yview, orient="vertical")
C.configure(yscrollcommand=S.set)
if sys.platform == "win32":
C.bind_all('<MouseWheel>', lambda event: C.yview_scroll(int(-1 * (event.delta / 120)), "units"))
elif sys.platform == "darwin":
C.bind_all('<MouseWheel>', lambda event: C.yview_scroll(int(event.delta), "units"))
elif sys.platform == "linux":
C.bind_all('<Button-4>', lambda event: C.yview('scroll', -1, 'units'))
C.bind_all('<Button-5>', lambda event: C.yview('scroll', 1, 'units'))
# create frame inside canvas
FF = Frame(C)
C.create_window((0, 0), window=FF, anchor=NW)
# create page content
for _ in range(100):
Label(FF,text="foo").pack()
Label(FF,text="bar").pack()
root.update()
C.config(scrollregion=C.bbox("all"))
mainloop()
【问题讨论】:
-
注意到您的某个绑定中的
-1了吗?将其交换到另一个绑定。 -
谢谢。成功了。
标签: python macos tkinter mousewheel macos-big-sur