如何将Tkinter窗口放置在其他窗口之上?

如何将Tkinter窗口放置在其他窗口之上?

每当我们创建一个GUI程序时,tkinter通常会将输出屏幕呈现在后台。换句话说,tkinter会在其他程序的后面显示程序窗口。为了将tkinter窗口放在其他窗口之上,我们需要使用 attributes(‘- topmost’,True) 属性。它会使窗口置顶。

示例

#导入库
from tkinter import *

#创建一个tkinter窗口
win= Tk()

#设置窗口的几何形状
win.geometry("600x350")

#创建一个标签
Label(win, text= "Hello World! ",font=('Helvetica bold', 15)).pack(pady=20)

#使窗口在所有窗口之上
win.attributes('-topmost',True)

win.mainloop()
Python

输出

运行上面的代码将使窗口始终处于所有其他窗口之上 −

如何将Tkinter窗口放置在其他窗口之上?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册