这是一段代码,它将回调排队Tk.after
,然后在执行回调之前销毁窗口:
import tkinter as tk
win = tk.Tk()
win.after(0, win.destroy)
win.after(200, lambda: None)
win.mainloop()
运行此代码通常不会产生任何输出:
Aran-Fey@DESKTOP-SJGQDQ8 /d/U/A/Desktop> python3 tkinter_demo.py
Aran-Fey@DESKTOP-SJGQDQ8 /d/U/A/Desktop>
但是如果解释器在执行此代码后进入交互模式,tkinter 会打印一条错误消息:
Aran-Fey@DESKTOP-SJGQDQ8 /d/U/A/Desktop> python3 -i tkinter_demo.py
>>> invalid command name "2256505886152<lambda>"
while executing
"2256505886152<lambda>"
("after" script)
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
为什么会发生这种情况,我该怎么办?