wm attributes

wm attributes window
wm attributes window option
wm attributes window option value ?option value...?

This subcommand returns or sets platform specific attributes associated with a window. The first form returns a list of the platform specific flags and their values. The second form returns the value for the specific option. The third form sets one or more of the values. The values are as follows:


This command exists since Tk 8.4 and sets or retrieves window-specific attributes. The supported attributes are different for each platform. On Tk 8.5, they are:

Macintosh Attributes

-alpha double
controls opacity (from 0.0 to 1.0)
-fullscreen boolean
controls whether the window takes the whole screen
-modified boolean
controls whether the window is marked as being modified (different close button)
-notify boolean
controls whether the window's icon bounces in the dock
-titlepath filename
associates a (draggable) file icon with the window title that can be used to manage the given file with other applications
-topmost boolean
controls whether the window stays on top of normal windows
-transparent boolean
controls whether the window has a shadow (useful for transparent windows, though care must be taken to draw appropriately to take advantage)

bll 2016-4-22: As of 2016-4-22, -fullscreen on Mac OS X must be preceded by wm withdraw . and followed by wm deiconify ..

Unix/X11 Attributes

-alpha double
controls opacity (from 0.0 to 1.0). This requires a compositing window manager to have any effect. compiz is one such, and xfwm4 (for the XFCE desktop) is another.
-fullscreen boolean
controls whether this window occupies the entire screen (different to -zoomed)
-topmost boolean
controls whether this window stays on top of other (normal) windows
-type list
this is provided in Tk 8.6, 8.5.9+ and 8.4.20+ to support the extended window manager hint property that governs a toplevel window's type on X11. Setting this appropriately can permit the window manager to apply relevant styling and animation. For instance, tooltip windows may well have animations to be used when mapping and unmapping the tooltip. Combobox dropdown lists have a different style to dialogs. The value for this attribute should be set to a list of preferred window types as not all window managers may support all types. Typically this is one of dialog, tooltip, combo or splash but anything from [L1 ] should be applicable. See [L2 ] for details.
-zoomed boolean
controls whether this window is in the zoomed state

NOTE: Support for all of these attributes depends on the system window manager; most do support, but not all.

Windows Attributes

Most options take a true/false value

-alpha double
how opaque the overall window is; note that changing between 1.0 and any other value may cause the window to flash (Tk changes the class of window used to implement the toplevel).
-fullscreen boolean
controls whether the window fills the whole screen, including taskbar
-disabled boolean
makes it impossible to interact with the window and redraws the focus
-toolwindow boolean
makes a window with a single close-button (which is smaller than usual) on the right of the title bar
-topmost boolean
makes sure the window always stays on top of all other windows

Example retrieving the default values:

 if 0 {
 % wm attributes .
 -disabled 0 -toolwindow 0 -topmost 0
 }

RS confirms that this applies to Windows 2000 too.

KPV a toolwindow window differs from a transient window in that the transient window still has the system menu and a transient window is always above its master window (at least for W2K).


RS 2005-05-31: Recent Tk (see Changes in Tcl/Tk 8.4.8) on Windows XP have an -alpha attribute that controls, between 0.0 (invisible, fully transparent) and 1.0 (regular, fully opaque), how opaque a window is. Here's a little testing script that is quite fascinating to watch:

 package require Tk
 pack [label .l -text "Hello, world" -font {Times 36}]
 update
 while 1 {
    for {set a 1.} {$a>0.} {set a [expr $a-0.01]} {
        wm attrib . -alpha $a; update; after 100
    }
    for {set a 0.} {$a<1.} {set a [expr $a+0.01]} {
        wm attrib . -alpha $a; update; after 100
    }
 }

MG puts out some thoughts (although ramblings is probably more accurate) on May 31 2005 (which probably apply only to MS Windows, and not MacOS/*nix). The -toolwindow option (and the wm overrideredirect command, which although not part of wm attributes is along the same lines) both remove the window's icon from the taskbar - is that unavoidable (ie, part of the same piece of OS code that does the rest of the functionality), or is it just done that way in Tk? If the latter, would it be possible to remove that, and make it another option for wm attributes? It would be good if you could remove the WM decorations, or get a "toolwindow", but still keep the window on the task bar (both so it doesn't get "lost" under other windows and become difficult to select again, and so you can have a main window that's just slightly more slimline, without full WM decorations).

AF Says the toolwindow display style is controlled by Windows, Tk only sets its window class.

Alex Collins There's a bug in certain versions of windows (2000?) that mean is you mix -toolwindow with a wm title, you cannot control the geometry correctly. aricb For best results, you should report this bug at SourceForge [L3 ].


AMG: See Transparent Toplevel for help on using -alpha to make a transparent toplevel window. See Strange Phenomen for discussion of transparent windows going opaque due to the event loop being blocked for too long.