在下面的代碼中,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()