0
我收到以下错误:_tkinter.TclError:无效的命令名称” 0.14574424"
_tkinter.TclError: invalid command name “.14574424”
我无法理解的错误。我究竟做错了什么?
# Import tkinter
from tkinter import *
class AnimationDemo:
def __init__(self):
window = Tk() # Create a window
window.title("Animation Demo") # Set a title
width = 250 # Width of the canvas
canvas = Canvas(window, bg = "white", width = 250, height = 50)
canvas.pack()
x = 0 # Starting x position
canvas.create_text(x, 30, text = "Message moving?", tags = "text")
dx = 3
while True:
canvas.move("text", dx, 0) # Move text dx unit
canvas.after(100) # Sleep for 100 milliseconds
canvas.update() # Update canvas
if x < width:
x += dx # Get the current position for string
else:
x = 0 # Reset string position to the beginning
canvas.delete("text")
# Redraw text at the beginning
canvas.create_text(x, 30, text = "Message moving?", tags = "text")
window.mainloop() # Create an event loop
AnimationDemo() # Create GUI
错误:回溯(最近通话最后一个): 文件“d :/sem4/t/lesson4/task1/task.py“,第29行,在 AnimationDemo()#创建GUI 文件”D:/sem4/t/lesson4/task1/task.py“,第17行,in __init__ canvas.move(“text”,dx,0)#移动文本dx单位 F (self._w,'move')+移动到第一行,然后移动到第一行, args) _tkinter.TclError:无效的命令名称“.14440096” –
hss
你在做什么导致错误?顺便说一句,这是用Tkinter做动画的错误方法。见http://stackoverflow.com/a/11505034/7432 –
谢谢@BryanOakley,但我可以知道为什么它显示错误,如果我们使用while循环 – hss