如何在 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()输出
如果我们运行上述代码,它将在主窗口前显示一个顶级窗口。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP