Invalid command name while executing (“after” script)

筅森魡賤 提交于 2019-12-04 04:41:59

问题


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.

Code:

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()

A message in console:

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

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"


回答1:


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.

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.




回答2:


I had this problem because my module was named "setup" and I also had a setup.py file. When calling setup.py somecommand, you will get "invalid command name 'somecommand'".



来源:https://stackoverflow.com/questions/26168967/invalid-command-name-while-executing-after-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!