在下面的代码中,tk
不是由函数launch()
创建的Toplevel
对象的父代。但是,当我使用tk.destroy()
销毁tk
时,Toplevel窗口消失。为什么Tkinter Toplevel物体被破坏?
Toplevel寡妇被摧毁了吗?如果是这样,Toplevel.destroy()
如何被调用?
from tkinter import *
def launch():
Toplevel()
tk = Tk()
frame = Frame(tk, relief="ridge", borderwidth=2)
frame.pack(fill="both", expand=1)
label = Label(frame, text="Hello, World")
label.pack(fill=X, expand=1)
button1 = Button(frame, text="Exit", command=tk.destroy)
button2 = Button(frame, text="Launch", command=launch)
button1.pack(side="bottom")
button2.pack(side="bottom")
tk.mainloop()