Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use wm attributes for Tkinter?

Tags:

python

tkinter

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.

like image 507
Pigman168 Avatar asked Feb 08 '23 17:02

Pigman168


1 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.

like image 70
Pigman168 Avatar answered Feb 15 '23 10:02

Pigman168