我对 Tkinter 的canvas.coords()
方法有疑问。我试图每 1/60 秒更新一次画布,并尝试检测何时按下右箭头键。问题是当我按住右箭头一段时间时出现错误:
http://postimage.org/image/bdfk3m8gx/
我的脚本是“novo.py”,代码如下。有什么帮助吗?我只是一个初学者。
import Tkinter, threading, time
def real_time(td, canvas):
while True:
time.sleep(1/60.0)
canvas.coords('line',1,1,200,200)
def func(event):
print 'key pressed'
root = Tkinter.Tk()
canvas = Tkinter.Canvas(root)
canvas.pack()
canvas.create_line(1,1,100,100, tag='line')
root.bind('<Right>', func)
thread = threading.Thread(target = real_time, args = (1/60.0, canvas))
thread.start()
root.mainloop()