How do I use Window Manager (wm) attributes in Tkinter?

TkinterPythonGUI-Programming

The Window Manager is a toolkit available in Tcl/Tk that can be accessed with the command 'wm'. The 'wm' command allows you to set the appearance and geometry of the Tkinter window. We can control the title, color, size, and other attributes with this command. The 'wm' command has numerous keywords that can be used to modify its property.

Example

# 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()

Output

If you run the above code, it will display a topmost transparent window that you cannot interact with, as the window is disabled using the wm attribute "-disabled".

raja
Published on 05-Aug-2021 14:12:40
Advertisements