执行时无效的命令名称(“after"脚本) [英] Invalid command name while executing ("after" script)

查看:145
本文介绍了执行时无效的命令名称(“after"脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为解决这个问题?我正在运行此代码,创建了窗口,但在控制台中出现了有关错误的消息.我认为问题是after"循环没有终止但窗口已经被破坏.

As solve this problem? I'm running this code, window is created, but in console appears message on the error. I think problem the fact that is "after" loop not terminate but the window already destroyed.

代码:

import Tkinter as tk
import time

class App():
    def __init__(self):
        self.root = tk.Tk()
        self.label = tk.Label(text="")
        self.label.pack()
        self.update_clock()
        self.root.mainloop()

    def update_clock(self):
        now = time.strftime("%H:%M:%S")
        self.label.configure(text=now)
        self.root.after(1000, self.update_clock)

app=App()

控制台中的消息:

invalid command name "66120320callit"
while executing
"66120320callit"
("after" script)

对不起,我在第一篇文章中提供了一些小信息.我正在使用 Spyder IDE,并且在 spyder 控制台中看到错误,其中重复运行我的代码.我在 python 错误跟踪器中发现的这个错误描述为wait_variable 在退出时挂起"

Sorry for my small information in first post. I'm using Spyder IDE, and bugs see in spyder console, wherein run repeatedly my code. A description this bugs I find in the python bug tracker as "wait_variable hangs at exit"

推荐答案

如果您销毁窗口,则任何已安排的之后"作业都可能运行.如果窗口被销毁并且此作业与已删除的小部件交互,您将收到此错误.

If you destroy the window, whatever "after" jobs that have already been scheduled may run. If the window is destroyed and this job interacts with a widget that has been deleted, you'll get this error.

您可以在代码周围放置一个 try 并忽略此类错误,在尝试配置之前检查窗口是否存在,或者在主窗口被销毁时放置一个处理程序以删除任何待处理的之后"工作.

You can either put a try around the code and ignore such an error, check that the window exists before trying to configure it, or put a handler in for when the main window is destroyed to delete any pending "after" jobs.

这篇关于执行时无效的命令名称(“after"脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆