How do I use wm attributes for Tkinter?

Question:

What are the parameters & options available for the window manager of Tkinter?

This Q&A is for those that found it hard to use the window manager and locate all the information on how to use it properly. If I’ve made any mistakes or missed something feel free to edit/comment.

Asked By: Pigman168

||

Answers:

Here is a quick overview of how to use the wm (window manager) call function:

#!/usr/bin/python3

from Tkinter import *
frame = Tk()

frame.overrideredirect(1) # Remove shadow & drag bar. Note: Must be used before wm calls otherwise these will be removed.

frame.call("wm", "attributes", ".", "-topmost", "true") # Always keep window on top of others
frame.geometry("100x100+500+500") # Set offset from top-left corner of screen as well as size
frame.call("wm", "attributes", ".", "-transparent", "true") # Remove shadow from window
frame.call("wm", "attributes", ".", "-fullscreen", "true") # Fullscreen mode
frame.call("wm", "attributes", ".", "-alpha", "0.9") # Window Opacity 0.0-1.0
frame.call("wm", "attributes", ".", "-modified", "0.9") # Toggles modified state of the close-window icon.

frame.mainloop()

The “.” is the ‘path’ to the window name in case it is a child of another window. For example if window “myFrame” had a child called “popup” then the path would read as “myFrame.popup”. The values true and false can be replaced with 1 and 0 respectively. Note: 1 and 0 do not need quotation marks.

See more about the wm attributes here and which ones are for which platform. Some are only available for windows.

Answered By: Pigman168
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.