【发布时间】:2014-12-05 15:44:35
【问题描述】:
我正在尝试使用 after_cancel 在简单的图像查看器中停止动画循环。我已经阅读了关于 Tcl 的文档,在这里和谷歌搜索,并探索了 python subreddits。我的错误是:
TclError: wrong # args: should be "after cancel id|command"
这发生在以下代码的最后一行(请不要因为使用全局变量而杀了我,这个项目只是一个图像查看器,用于显示我们办公室的天气预报产品):
n_images = 2
images = [PhotoImage(file="filename"+str(i)+".gif") for i in range(n_images)]
current_image = -1
def change_image():
displayFrame.delete('Animate')
displayFrame.create_image(0,0, anchor=NW,
image=images[current_image], tag='Animate')
displayFrame.update_idletasks() #Force redraw
callback = None
def animate():
forward()
callback = root.after(1000, animate)
def forward():
global current_image
current_image += 1
if current_image >= n_images:
current_image = 0
change_image()
def back():
global current_image
current_image -= 1
if current_image < 0:
current_image = n_images-1
change_image()
def stop():
root.after_cancel(callback)
如果有更合适的方法来停止 Tkinter 中的动画循环,请告诉我!
【问题讨论】:
-
stop在哪里被调用? -
在回应您对我对这个问题的上一版本的回答stackoverflow.com/questions/27297814/… 的评论时,我说动画需要@987654325@ 添加并编辑到我的回答中。
标签: python python-2.7 tkinter pillow