如何在 Tkinter 中將頂級視窗置於主視窗前?
Tkinter 頂級視窗會在主視窗之外建立一個新視窗。我們可以在新建立的頂級視窗中新增小元件和元件。它支援父視窗或主視窗的所有屬性。
有時,頂級視窗也稱為子視窗。若要將子視窗放在父視窗的前面,我們可以使用 wm_transient() 方法。
示例
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") win.title("Parent Window") # Create a Toplevel window top=Toplevel(win) top.geometry('600x250') top.title("Child Window") # Place the toplevel window at the top top.wm_transient(win) win.mainloop()
輸出
如果我們執行上述程式碼,它將在主視窗前顯示一個頂級視窗。
廣告