【发布时间】:2023-01-29 10:55:25
【问题描述】:
我正在尝试使用和绑定来制作侧边栏,如果我将鼠标移动得更慢,一切正常,但如果我使用鼠标移动得更快,侧边栏就会开始不停地来回移动。有办法解决吗?
(一般来说,我是 tkinter 和 python 的新手) 1/2 2/2
from tkinter import *
#主窗口 定义主窗口(): 全局窗口主
WindowMain = Tk()
WindowMain.config(background="LightGray")
WindowMain.overrideredirect(1)
#MainWindow_size
def Screen_size():
app_width = 1280
app_height = 720
screen_width = WindowMain.winfo_screenwidth()
screen_height = WindowMain.winfo_screenheight()
x = (screen_width / 2) - (app_width / 2)
y = (screen_height / 2) - (app_height / 2)
WindowMain.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')
#Func1
def close(e):
for x in range(1000, 1200):
Blue.place(x=x, y=0)
DarkBlue.place(x=x, y=0)
Blue.update()
DarkBlue.update()
Blue.bind("<Enter>", open)
#Func2
def open(e):
for x in range(-1200, -1000):
Blue.place(x=-x, y=0)
DarkBlue.place(x=-x, y=0)
Blue.update()
DarkBlue.update()
Blue.bind("<Leave>", close)
MainWindow()
Screen_size()
#Label1&2
Blue = Label(WindowMain, background="DeepSkyBlue",
width=70, height=50)
DarkBlue = Label(WindowMain, width=2, height=100,
background="DodgerBlue")
Blue.place(x=1200)
DarkBlue.place(x=1200)
#Buttons
Quit = Button(WindowMain, text="Quit", command=quit,
background="LightSkyBlue").pack()
Move = Button(WindowMain, text="open", command=open,
background="LightSkyBlue", state=DISABLED).pack()
Undo = Button(WindowMain, text="close", command=close,
background="LightSkyBlue", state=DISABLED).pack()
Blue.bind("<Enter>", open)
WindowMain.mainloop()
【问题讨论】:
-
你能把代码贴出来吗?我们需要查看代码才能提供帮助
-
你可以点击照片链接来查看
-
请在问题正文中包含代码而不是屏幕截图。
-
如果您阅读How to ask 它说:不要张贴代码、数据、错误消息等的图像 - 将文本复制或键入问题中。
-
查看
after方法并避免使用循环和update