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

The Window Manager (wm) is a toolkit available in Tcl/Tk that provides control over window appearance and behavior. In Tkinter, you can access these features using the wm_attributes() method to modify properties like transparency, window state, and interaction behavior.

Basic Window Manager Attributes

The wm_attributes() method accepts attribute-value pairs to control window properties. Here are the most commonly used attributes −

Example

# Import the required library
from tkinter import *

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

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

Label(win, text="This window has special attributes.",
      font=("Calibri", 24)).pack(pady=50)

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

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

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

win.mainloop()

Common WM Attributes

Attribute Description Example Values
-alpha Window transparency 0.0 (invisible) to 1.0 (opaque)
-topmost Keep window above others True or False
-disabled Disable user interaction True or False
-fullscreen Toggle fullscreen mode True or False

Multiple Attributes Example

from tkinter import *

def toggle_topmost():
    current = win.wm_attributes('-topmost')
    win.wm_attributes('-topmost', not current)

def change_alpha():
    current = win.wm_attributes('-alpha')
    new_alpha = 0.5 if current == 1.0 else 1.0
    win.wm_attributes('-alpha', new_alpha)

win = Tk()
win.geometry("400x200")
win.title("WM Attributes Demo")

Button(win, text="Toggle Topmost", command=toggle_topmost).pack(pady=10)
Button(win, text="Toggle Transparency", command=change_alpha).pack(pady=10)

# Set initial attributes
win.wm_attributes('-topmost', False)
win.wm_attributes('-alpha', 1.0)

win.mainloop()

Platform-Specific Attributes

Some attributes are platform-specific. On Windows, you might have additional options −

# Windows-specific attributes
win.wm_attributes('-toolwindow', True)  # Remove from taskbar
win.wm_attributes('-transparentcolor', 'white')  # Make color transparent

Conclusion

Window Manager attributes provide powerful control over Tkinter window behavior. Use wm_attributes() to create transparent, topmost, or disabled windows for enhanced user interfaces.

Updated on: 2026-03-26T00:09:44+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements