简体   繁体   English

tkinter.after() 无效命令名称

[英]tkinter .after() invalid command name

I work on Python 3.10.2 and I just start to work with tkinter and I always have a problem with.after() method.我在 Python 3.10.2 工作,我刚开始使用 tkinter,我总是遇到 .after() 方法的问题。 For example with this program:例如这个程序:

import tkinter as tk

def initialisation(compteur) :
    compteur=compteur+1
    print(compteur)
    root.after(2000,initialisation, compteur)

root=tk.Tk()    
initialisation(0)
root.mainloop()

I have this error:我有这个错误:

1

invalid command name "1720125185344initialisation"
    while executing
"1720125185344initialisation"
    ("after" script)
2
3

It works but I still have this error 1 time.它有效,但我仍然遇到此错误 1 次。 I have looked for solutions but I don't understand.我一直在寻找解决方案,但我不明白。 Thank you in advance for your help.预先感谢您的帮助。

try adding del root at the end of the script:尝试在脚本末尾添加del root

import tkinter as tk

def initialisation(compteur) :
    compteur=compteur+1
    print(compteur)
    root.after(2000,initialisation, compteur)

root=tk.Tk()    
initialisation(0)
root.mainloop()

del root

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM