我是tkinter的新手,正在尝试制作一个基本的绘图应用程序。但是,当我四处移动光标时,有时会突然停止绘制,然后仅在几秒钟后显示完成的线。这显示在这里。
https://www.youtube.com/edit?video_referrer=watch&video_id=_g8n55V6qPQ
这是滞后吗?否则,我的笔记本电脑可以很好地运行,甚至可以在刚开始时``滞后''(即在画布上没有任何其他对象之前)。如果只是滞后,那么在制作python绘图应用程序时我应该采取哪种解决方法?
这是我的代码:
from tkinter import *
root = Tk()
root.title("Note Taking")
can_width = 800
can_height = 800
canvas = Canvas(root, width=can_width, height=can_height, bg='white')
canvas.pack(padx=20, pady=20)
class g():
points = []
user_line = None
drawing = False
t = 0
def leftClick(event):
g.points = []
g.user_line = None
g.drawing = True
g.points.append(event.x)
g.points.append(event.y)
def leftMove(event):
# Print out an increasing number: t, so I can see it in the output
print(g.t)
g.t+=1
if g.drawing:
g.points.append(event.x)
g.points.append(event.y)
if g.user_line == None:
g.user_line = canvas.create_line(g.points, width=4, smooth=1)
else:
canvas.coords(g.user_line, g.points)
def leftRelease(event):
g.points = []
g.user_line = None
canvas.bind('<Button-1>', leftClick)
canvas.bind('<B1-Motion>', leftMove)
canvas.bind('<ButtonRelease-1>', leftRelease)
root.mainloop()