如何在 Tkinter 中使用窗口管理器 (wm) 属性?


窗口管理器是 Tcl/Tk 中提供的一个工具包,可以使用命令 'wm' 访问。'wm' 命令允许你设置 Tkinter 窗口的外观和几何形状。我们可以使用这个命令来控制标题、颜色、大小和其他属性。'wm' 命令有许多关键字,可用于修改其属性。

示例

# Import the required library
from tkinter import *
from tkinter import ttk
from tkinter import messagebox

# Create an instance of tkinter frame
win=Tk()

# Set the geometry
win.geometry("700x350")

Label(win, text="This window is disabled.",
   font=("Calibri, 24")).pack()

# Makes the window topmost
win.wm_attributes('-topmost', True)

# Makes the window transparent
win.wm_attributes('-alpha', 0.9)

# Disable the window
win.wm_attributes('-disabled', True)

# Set the geometry of the window
win.wm_geometry('700x350')

win.mainloop()

输出

如果你运行以上代码,它将显示一个置顶的透明窗口,你无法与其交互,因为窗口已使用 wm 属性 "-disabled" 禁用。

更新时间: 2021 年 8 月 5 日

超过 4K 次浏览

开启您的职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.