我有一个调用此类的 drawWorld() 函数的外部脚本。我希望绘图显示 1-2 秒,然后关闭并且控件返回到主脚本。我可以设法让窗口随着线条消失
root.after(1000, lambda: root.destroy())
但我无法将流程返回到主脚本。我试过了
root.after(1000, lambda: root.quit())
但它不起作用。
这是我的 Tkinter 类代码:
from Tkinter import Tk, Canvas, Frame, BOTH
class World(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.parent.title("CliffWorld")
self.pack(fill=BOTH, expand=1)
canvas = Canvas(self)
canvas.create_rectangle(4, 4, 31, 31,
outline="#f11", fill="#1f1", width=1)
canvas.pack(fill=BOTH, expand=1)
def drawWorld():
root = Tk()
ex = World(root)
root.geometry("330x220+300+300")
root.after(1000, lambda: root.destroy())
root.after(1000, lambda: root.quit())
root.mainloop()