所以我想在光标后面创建一条线。我不想有前几帧的痕迹
root = Tk()
canvas = Canvas(root, width=720, height=720)
def mouseGetPos():
global root
relX = root.winfo_pointerx() - root.winfo_rootx()
relY = root.winfo_pointery() - root.winfo_rooty()
return [relX, relY]
while True:
canvas.pack()
canvas.create_line(0,0, mouseGetPos()[0],mouseGetPos()[1])
time.sleep(1/100)
root.update()
如何更新/刷新画布?我用这个做游戏
编写tkinter程序的正确方法是使用
mainloop
,而不是创建自己的游戏循环。这样,您就不必强制进行任何更新,屏幕将在事件之间自动更新然后可以绑定一个函数,以便在鼠标移动时调用。每次tkinter检测到事件时,都会调用您的函数
下面是一个工作示例:
这对我很有用:
制作一个标记-“行”,然后删除该行,以便获得所需的结果
我认为这是使用事件的最简单解决方案。这是基于@BryanOakley的答案
相关问题 更多 >
编程相关推荐