wm(3tk)
wm π your hotline to the window manager
okay so this is the wm page, from the Tk Built-In Commands collection. it's the command that lets your app actually talk to the window manager, and bestie, it does a LOT. let's go π«Ά
β¨ NAME β¨
wm β communicate with window manager πͺπ¬
β¨ SYNOPSIS β¨
wm option window ?args?
β¨ DESCRIPTION β¨
So the whole point of wm is interacting with window managers so you can control the lil' things that make a window feel like a window β its title, its geometry, the increments it gets resized in, all of that. The wm command shapeshifts into a bunch of different forms depending on what you pass as the option argument.
And every single one of those forms expects at least one more argument: window. That has to be the path name of a top-level window. no substitutes, no vibes-only guesses, it needs the real path name. periodt π
Here's every legal form the wm command can take:
wm aspect window ?minNumer minDenom maxNumer maxDenom?β IfminNumer,minDenom,maxNumer, andmaxDenomare all given, they get handed straight to the window manager, and the window manager should use them to enforce a range of acceptable aspect ratios forwindow. The aspect ratio ofwindow(that's width/length) gets constrained to sit betweenminNumer/minDenomandmaxNumer/maxDenom. IfminNumeretc. are all specified as empty strings, then any existing aspect ratio restrictions get removed β poof, gone. IfminNumeretc. are specified, the command returns an empty string. Otherwise (the no-args case), it returns a Tcl list with four elements: the current values ofminNumer,minDenom,maxNumer, andmaxDenom. And if no aspect restrictions are in effect at all? Then you just get an empty string back. π€·ββοΈwm attributes windowwm attributes window ?option?wm attributes window ?option value option value...?
This subcommand returns or sets platform specific attributes tied to a window. Three forms, three jobs:
- The first form returns a list of the platform specific flags and their values.
- The second form returns the value for the one specific option you asked about.
- The third form sets one or more of the values.
The values go as follows π
All platforms support the following attributes (though X11 users, heads up β peep the notes further down):
-alphaβ Specifies the alpha transparency level of the toplevel. It takes a value from0.0(fully transparent, ghost mode π») to1.0(opaque). Values outside that range get constrained β the range holds, no cap. Where it's not supported, the-alphavalue just stays parked at1.0.-fullscreenβ Puts the window into a mode that takes up the entire screen, has no borders, and covers the general use area (that's the Start menu and taskbar on Windows, the dock and menubar on macOS, and the general window decorations on X11). main character energy, literally owns the screen.-topmostβ Specifies whether this is a topmost window, meaning it displays above all other windows. floating above the drama, iconic.
On Windows, these attributes may be set:
-disabledβ Specifies whether the window is in a disabled state.-toolwindowβ Specifies a toolwindow style window (as defined in the MSDN).-transparentcolorβ Specifies the transparent color index of the toplevel. It takes any color value accepted byTk_GetColor. If the empty string is specified (which is the default), no transparent color is used. This is supported on Windows 2000/XP+. Where it's not supported, the-transparentcolorvalue stays at{}.
On macOS, these attributes may be set:
-appearanceβ Specifies whether the window is rendered in "dark mode". The allowed values areauto,aquaanddarkaqua. If the setting isauto, then the appearance of the window is controlled by the System Settings.-classβ Specifies whether the underlying Aqua window for a toplevel is an object of theNSWindowclass or theNSPanelclass. The two allowed values for this option arenswindowandnspanel. You cannot change the class of the underlying Aqua window once that window has been instantiated, and attempting to do that is an error. However! It is allowed to set this option for a pathname that doesn't correspond to an existing window. Doing that causes the class name to be cached for later use β so when a toplevel with that pathname eventually gets created, the cached class name decides which class is used for the underlying Aqua window. sneaky, but legal. π-isdarkβ Returns a boolean value which is true if the window is currently in dark mode.-modifiedβ Specifies the modification state of the window. This determines whether the window close widget contains the modification indicator and whether the proxy icon is draggable.-notifyβ Specifies process notification state (that's the bouncing of the application dock icon, yes the lil' boing boing).-stylemaskβ Specifies an integer to be assigned as thestyleMaskof the underlying Aqua window. (See the Apple documentation for thestyleMaskproperty of theNSWindowclass.) The value of this option should be a list of bitnames. Each bit named in the list gets set to1, and all other bits get set to0. The allowed bitnames are:titled,closable,miniaturizable,resizable,fullsizecontentview,docmodal,utility,nonactivatingpanel, andHUDwindow. Note that a side effect of setting thefullsizecontentviewbit is that the window title bar becomes transparent. β¨-tabbingidβ Controls how tabbed toplevel windows are grouped together. Two tabs in the same group must correspond to toplevels with the sametabbingid, which can be an arbitrary UTF8 string. In the Tk implementation, changing thetabbingidof a toplevel in a tab group will cause it to be moved into a different group, in which all tabs have the newtabbingidβ or, if the newtabbingidis unique, it becomes a normal non-tabbed toplevel. It is allowed to set thetabbingidbefore the toplevel is created. If the pathname provided in the command does not correspond to a toplevel, the value gets cached and used later when the toplevel is actually created.-tabbingmodeβ Controls whether a toplevel can be opened as a tab within a tab group. The allowed values areauto,preferredordisallowed. A toplevel can be opened as a tab in exactly two situations: if itstabbingmodeispreferred; or if itstabbingmodeisautoand the user has selected "prefer tabs when opening documents" in the Desktop and Dock panel of the System Settings application. It is allowed to set thetabbingmodebefore the toplevel is created. If the pathname provided in the command does not correspond to a toplevel, the value gets cached and used later when the toplevel is actually created.-titlepathβ Specifies the path of the file referenced as the window proxy icon (the one that can be dragged and dropped in lieu of the file's finder icon).-transparentβ Makes the window content area transparent and turns off the window shadow. For the transparency to actually be effective, the toplevel background needs to be set to a color with some alpha, e.g.systemTransparent. π»
On X11, these attributes may be set. Heads up though: these are not supported by all window managers, and they'll have no effect under older WMs. so vibe check your WM first bestie.
-typeβ Requests that the window should be interpreted by the window manager as being of the specified type(s). This may cause the window to be decorated in a different way or otherwise managed differently, though exactly what happens is entirely up to the window manager β you're making a request, not a demand. A list of types may be used, in order of preference. The following values are mapped to constants defined in the EWMH specification (using others is possible, but not advised):desktopβ indicates a desktop feature,dockβ indicates a dock/panel feature,toolbarβ indicates a toolbar window that should be acting on behalf of another window, as indicated withwm transient,menuβ indicates a torn-off menu that should be acting on behalf of another window, as indicated withwm transient,utilityβ indicates a utility window (e.g., palette or toolbox) that should be acting on behalf of another window, as indicated withwm transient,splashβ indicates a splash screen, displayed during application start up,dialogβ indicates a general dialog window, that should be acting on behalf of another window, as indicated withwm transient,dropdown_menuβ indicates a menu summoned from a menu bar, which should usually also be set to be override-redirected (withwm overrideredirect),
popup_menuβ bestie, this one indicates a popup menu π and it should usually also be set to be override-redirected (withwm overrideredirect), okay?tooltipβ indicates a tooltip window, which should usually also be set to be override-redirected (withwm overrideredirect). Yes, same little override-redirect moment πnotificationβ indicates a window that provides a background notification of some event, which should usually also be set to be override-redirected (withwm overrideredirect). She's just here to tell you something happened β¨comboβ indicates the drop-down list of a combobox widget, which should usually also be set to be override-redirected (withwm overrideredirect). The little list that pops down, iconic π«Άdndβ indicates a window that represents something being dragged, which should usually also be set to be override-redirected (withwm overrideredirect). Drag-and-drop representation, slay πnormalβ indicates a window that has no special interpretation. Just a regular girl, no lore πΈ-zoomedβ requests that the window should be maximized. This is the same aswm state zoomedon Windows and macOS. π
Okay so important X11 tea: on X11, changes to window attributes are performed asynchronously. Querying the value of an attribute returns the current state, which will not be the same as the value most recently set if the window manager has not yet processed the request or if it does not support the attribute. So like, don't be shocked when you read back something stale β that's just how it is, no cap π
wm client window ?name?
If name is specified, this command stores name (which should be the name of the host on which the application is executing) in window's WM_CLIENT_MACHINE property, so the window manager or session manager can use it. The command returns an empty string in this case.
If name is not specified, the command returns the last name set in a wm client command for window. And if name is specified as an empty string, the command deletes the WM_CLIENT_MACHINE property from window. Bye bestie π
wm colormapwindows window ?windowList?
This command is used to manipulate the WM_COLORMAP_WINDOWS property, which provides information to the window managers about windows that have private colormaps. Private colormaps, the drama πΈ
- If
windowListis not specified, the command returns a list whose elements are the names of the windows in theWM_COLORMAP_WINDOWSproperty. - If
windowListis specified, it consists of a list of window path names; the command overwrites theWM_COLORMAP_WINDOWSproperty with the given windows and returns an empty string. TheWM_COLORMAP_WINDOWSproperty should normally contain a list of the internal windows withinwindowwhose colormaps differ from their parents.
The order of the windows in the property indicates a priority order, periodt: the window manager will attempt to install as many colormaps as possible from the head of this list when window gets the colormap focus. If window is not included among the windows in windowList, Tk implicitly adds it at the end of the WM_COLORMAP_WINDOWS property, so that its colormap is lowest in priority. π
If wm colormapwindows is not invoked, Tk will automatically set the property for each top-level window to all the internal windows whose colormaps differ from their parents, followed by the top-level itself; the order of the internal windows is undefined, so literally do not rely on it. See the ICCCM documentation for more information on the WM_COLORMAP_WINDOWS property, iykyk π
wm command window ?value?
If value is specified, this command stores value in window's WM_COMMAND property for use by the window manager or session manager, and returns an empty string. value must have proper list structure; the elements should contain the words of the command used to invoke the application.
If value is not specified then the command returns the last value set in a wm command command for window. If value is specified as an empty string, the command deletes the WM_COMMAND property from window. π
wm deiconify window
Arrange for window to be displayed in normal (non-iconified) form. This is done by mapping the window. If the window has never been mapped then this command will not map the window, but it will ensure that when the window is first mapped it will be displayed in de-iconified form. So it's a promise for later, bestie π€
On Windows, a deiconified window will also be raised and be given the focus (made the active window). Returns an empty string. β¨
wm focusmodel window ?active|passive?
If active or passive is supplied as an optional argument to the command, then it specifies the focus model for window. In this case the command returns an empty string. If no additional argument is supplied, then the command returns the current focus model for window.
An active focus model means that window will claim the input focus for itself or its descendants, even at times when the focus is currently in some other application. Passive means that window will never claim the focus for itself: the window manager should give the focus to window at appropriate times. However, once the focus has been given to window or one of its descendants, the application may re-assign the focus among window's descendants.
The focus model defaults to passive, and Tk's focus command assumes a passive model of focusing. Main character energy is opt-in, okay? π
wm forget window
The window will be unmapped from the screen and will no longer be managed by wm. Windows created with the toplevel command will be treated like frame windows once they are no longer managed by wm, however, the -menu configuration will be remembered and the menus will return once the widget is managed again. She'll be back, and her menus will be back too π
wm frame window
If window has been reparented by the window manager into a decorative frame, the command returns the platform specific window identifier for the outermost frame that contains window (the window whose parent is the root or virtual root).
If window has not been reparented by the window manager then the command returns the platform specific window identifier for window. Either way you get an ID, just which ID is the plot twist π¦
wm geometry window ?newGeometry?
If newGeometry is specified, then the geometry of window is changed and an empty string is returned. Otherwise the current geometry for window is returned (this is the most recent geometry specified either by manual resizing or in a wm geometry command).
newGeometry has the form =widthxheightΒ±xΒ±y, where any of =, widthxheight, or Β±xΒ±y may be omitted. width and height are positive integers specifying the desired dimensions of window. If window is gridded (see GRIDDED GEOMETRY MANAGEMENT below) then the dimensions are specified in grid units; otherwise they are specified in pixel units.
x and y specify the desired location of window on the screen, in pixels. If x is preceded by +, it specifies the number of pixels between the left edge of the screen and the left edge of window's border; if preceded by - then x specifies the number of pixels between the right edge of the screen and the right edge of window's border. If y is preceded by + then it specifies the number of pixels between the top of the screen and the top of window's border; if y is preceded by - then it specifies the number of pixels between the bottom of window's border and the bottom of the screen. So plus is "from the left/top" and minus is "from the right/bottom", and yes that trips everyone up at least once π
If newGeometry is specified as an empty string then any existing user-specified geometry for window is cancelled, and the window will revert to the size requested internally by its widgets. Reset era πΈ
Note that this is related to winfo geometry, but not the same. That one can only query the geometry, and always reflects Tk's current understanding of the actual size and location of window, whereas wm geometry allows both setting and querying of the window manager's understanding of the size and location of the window. This can vary significantly, for example to reflect the addition of decorative elements to window such as title bars, and window managers are not required to precisely follow the requests made through this command. So yeah, you ask nicely, the WM does what it wants π
wm grid window ?baseWidth baseHeight widthInc heightInc?
This command indicates that window is to be managed as a gridded window. It also specifies the relationship between grid units and pixel units.
baseWidth and baseHeight specify the number of grid units corresponding to the pixel dimensions requested internally by window using Tk_GeometryRequest. widthInc and heightInc specify the number of pixels in each horizontal and vertical grid unit. These four values determine a range of acceptable sizes for window, corresponding to grid-based widths and heights that are non-negative integers. Tk will pass this information to the window manager; during manual resizing, the window manager will restrict the window's size to one of these acceptable sizes.
Furthermore, during manual resizing the window manager will display the window's current size in terms of grid units rather than pixels. If baseWidth etc. are all specified as empty strings, then window will no longer be managed as a gridded window. If baseWidth etc. are specified then the return value is an empty string.
Otherwise the return value is a Tcl list containing four elements corresponding to the current baseWidth, baseHeight, widthInc, and heightInc; if window is not currently gridded, then an empty string is returned. Grid math bestie, it's giving geometry but make it snap π₯
Also, real talk bestie: you probably won't need this command very often, because theTk_SetGridlibrary procedure and thesetGridoption give you easier access to the same functionality. π
wm group π
wm group window ?pathName?
If you pass a pathName, it's the path name for the leader of a group of related windows. The window manager might use this info to, like, unmap all the windows in a group when the group's leader gets iconified. You can pass an empty string for pathName to remove window from any group association. If you do specify pathName, the command returns an empty string. Otherwise, it returns the path name of window's current group leader, or an empty string if window isn't part of any group. Periodt. β¨
wm iconbadge π
wm iconbadge window badge
Sets a badge for the icon of the window. The badge can be a positive integer number β like, say, the number of new or unread messages β or an exclamation point denoting attention needed. If the badge is an empty string, the badge image is removed from the application icon. Managing these changes through bindings, such as <FocusIn>, is the responsibility of the developer. π
On X11, for this command to work, the variable ::tk::icons::base_icon($window) must be set to the image that is being used for the window icon of $window. On Windows and X11, the iconphoto images work best at 32x32 or a similar dimension, as the badge images are provided by Tk and drawn to overlay the icon images using native (Windows) API's or Tk rendering. On macOS, the icon badge is rendered by a system API and is not provided by Tk. The icon image itself should be higher-resolution, preferably 512 pixels, to avoid being blurry. β¨
The icon badge is intended for display in the Dock (macOS), taskbar (Windows) or app panel (X11). On macOS, the last badge called will be displayed in the Dock, regardless of how many different icon badges may be assigned to different windows. On Windows, the taskbar display depends on whether the taskbar buttons are combined or not (this is an OS setting available to the user): if combined, the behavior is the same as on macOS, otherwise each button in the taskbar shows the badge it was assigned. Badge display on macOS is configured in the system preferences. App panel display behavior on X11 will depend on the window manager and/or desktop environment. π
wm iconbitmap π
wm iconbitmap window ?bitmap?
If bitmap is specified, then it names a bitmap in the standard forms accepted by Tk (see the Tk_GetBitmap manual entry for details). This bitmap is passed to the window manager to be displayed in window's icon, and the command returns an empty string. If an empty string is specified for bitmap, then any current icon bitmap is cancelled for window. If bitmap is specified then the command returns an empty string. Otherwise it returns the name of the current icon bitmap associated with window, or an empty string if window has no icon bitmap. On the Windows operating system, an additional flag is supported:
wm iconbitmap window ?-default? ?image?
If the -default flag is given, the icon is applied to all toplevel windows (existing and future) to which no other specific icon has yet been applied. In addition to bitmap image types, a full path specification to any file which contains a valid Windows icon is also accepted (usually .ico or .icr files), or any file for which the shell has assigned an icon. Tcl will first test if the file contains an icon, then if it has an assigned icon, and finally, if that fails, test for a bitmap. π
wm iconify π΄
wm iconify window
Arrange for window to be iconified. If window has not yet been mapped for the first time, this command will arrange for it to appear in the iconified state when it is eventually mapped. π¦
wm iconmask π
wm iconmask window ?bitmap?
If bitmap is specified, then it names a bitmap in the standard forms accepted by Tk (see the Tk_GetBitmap manual entry for details). This bitmap is passed to the window manager to be used as a mask in conjunction with the iconbitmap option: where the mask has zeroes no icon will be displayed; where it has ones, the bits from the icon bitmap will be displayed. If an empty string is specified for bitmap then any current icon mask is cancelled for window (this is equivalent to specifying a bitmap of all ones). If bitmap is specified then the command returns an empty string. Otherwise it returns the name of the current icon mask associated with window, or an empty string if no mask is in effect. πΈ
wm iconname π·οΈ
wm iconname window ?newName?
If newName is specified, then it is passed to the window manager; the window manager should display newName inside the icon associated with window. In this case an empty string is returned as result. If newName is not specified then the command returns the current icon name for window, or an empty string if no icon name has been specified (in this case the window manager will normally display the window's title, as specified with the wm title command). π
wm iconphoto πΈ
wm iconphoto window ?-default? image1 ?image2 ...?
Sets the titlebar icon for window based on the named photo images. If -default is specified, this is applied to all future created toplevels as well. The data in the images is taken as a snapshot at the time of invocation. If the images are later changed, this is not reflected to the titlebar icons. Multiple images are accepted to allow different images sizes (e.g., 16x16 and 32x32) to be provided. The window manager may scale provided icons to an appropriate size. β¨
On Windows, the images are packed into a Windows icon structure. This will override an ico specified to wm iconbitmap, and vice versa. This command sets the taskbar icon for the window. πͺ
On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A wm iconbitmap may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first. This command also sets the panel icon for the application if the window manager or desktop environment supports it. π₯οΈ
On Macintosh, the first image called is loaded into an OS-native icon format, and becomes the application icon in dialogs, the Dock, and other contexts. At the script level the command will accept only the first image passed in the parameters as support for multiple sizes/resolutions on macOS is outside Tk's scope. Developers should use the largest icon they can support (preferably 512 pixels) to ensure smooth rendering on the Mac. π
wm iconposition π
wm iconposition window ?x y?
If x and y are specified, they are passed to the window manager as a hint about where to position the icon for window. In this case an empty string is returned. If x and y are specified as empty strings then any existing icon position hint is cancelled. If neither x nor y is specified, then the command returns a Tcl list containing two values, which are the current icon position hints (if no hints are in effect then an empty string is returned). πΊοΈ
wm iconwindow πͺ
wm iconwindow window ?pathName?
If pathName is specified, it is the path name for a window to use as icon for window: when window is iconified then pathName will be mapped to serve as icon, and when window is de-iconified then pathName will be unmapped again. If pathName is specified as an empty string then any existing icon window association for window will be cancelled. If the pathName argument is specified then an empty string is returned. Otherwise the command returns the path name of the current icon window for window, or an empty string if there is no icon window currently specified for window. Button press events are disabled for window as long as it is an icon window; this is needed in order to allow window managers to βownβ those events. Note that not all window managers support the notion of an icon window, and the concept is entirely meaningless on non-X11 platforms. π
wm manage π
wm manage widget
The widget specified will become a stand alone top-level window. The window will be decorated with the window managers title bar, etc. Only frame, labelframe and toplevel widgets can be used with this command. Attempting to pass any other widget type will raise an error. Attempting to manage a toplevel widget is benign and achieves nothing. See also GEOMETRY MANAGEMENT. π
wm maxsize π
wm maxsize window ?width height?
If width and height are specified, they give the maximum permissible dimensions for window. For gridded windows the dimensions are specified in grid units; otherwise they are specified in pixel units. The window manager will restrict the window's dimensions to be less than or equal to width and height. If width and height are specified, then the command returns an empty string. Otherwise it returns a Tcl list with two elements, which are the maximum width and height currently in effect. The maximum size defaults to the size of the screen. See the sections on geometry management below for more information. π₯
wm minsize π
wm minsize window ?width height?
If width and height are specified, they give the minimum permissible dimensions for window. For gridded windows the dimensions are specified in grid units; otherwise they are specified in pixel units. The window manager will restrict the window's dimensions to be greater than or equal to width and height. If width and height are specified, then the command returns an empty string. Otherwise it returns a Tcl list with two elements, which are the minimum width and height currently in effect. The minimum size defaults to one pixel in each dimension. See the sections on geometry management below for more information. π
wm overrideredirect π¦
wm overrideredirect window ?boolean?
okay so if you pass boolean, bestie, it's gotta be in a proper boolean form, and the override-redirect flag for window gets set to that value. periodt. If you don't pass boolean, you get back 1 or 0, which tells you whether or not that override-redirect flag is currently set for window.
So what does setting the override-redirect flag even do? It makes the window get completely ignored by the window manager. Which is giving very much "I don't need a chaperone" energy. Among other things, this means:
- the window will not be reparented from the root window into a decorative frame, and
- the user will not be able to manipulate the window using the normal window manager mechanisms.
β οΈ Heads up though: the override-redirect flag is only guaranteed to be taken notice of when the window is first mapped, or when it's mapped after the state is changed fromwithdrawntonormal. Some platforms (but like, not all of them) will take notice at additional times. So don't come crying to me if your platform is built different. π
wm positionfrom π
wm positionfrom window ?who?
If who is specified it's gotta be either program or user, or an abbreviation of one of those two. It tells you whether window's current position was requested by the program or by the user. π
Why does this matter? Because many window managers ignore program-requested initial positions and instead make the user manually position the window. So if you specify user, the window manager should position the window at the given place without asking the user for assistance. No questions asked, slay.
- If
whois specified as an empty string, then the current position source is cancelled. - If
whois specified, the command returns an empty string. - Otherwise it returns
userorprogramto indicate the source of the window's current position β or an empty string if no source has been specified yet.
Most window managers interpret "no source" as equivalent to program. And plot twist: Tk will automatically set the position source to user when a wm geometry command is invoked, unless the source has been set explicitly to program. iykyk. β¨
wm protocol π«Ά
wm protocol window ?name? ?command?
This one manages window manager protocols. The name argument here is the name of an atom corresponding to a window manager protocol. Examples include WM_DELETE_WINDOW or WM_SAVE_YOURSELF or WM_TAKE_FOCUS.
A window manager protocol is a class of messages sent from a window manager to a Tk application outside of the normal event processing system. The main example is the WM_DELETE_WINDOW protocol β these messages are sent when the user clicks the close widget in the title bar of a window. Handlers for window manager protocols get installed with the wm protocol command.
As a rule: if no handler has been installed for a protocol by the wm protocol command, then all messages of that protocol are ignored. The WM_DELETE_WINDOW protocol is an exception to this rule β at start-up Tk installs a handler for this protocol, which responds by destroying the window. The wm protocol command can be used to replace this default handler with one that responds differently. π₯
The list of available window manager protocols depends on the window manager, but all window managers supported by Tk provide WM_DELETE_WINDOW. On the Windows platform, a WM_SAVE_YOURSELF message is sent on user logout or system restart.
Now the actual behaviour, bestie, and it's lowkey a choose-your-own-adventure:
- If both
nameandcommandare specified, thencommandbecomes the handler for the protocol specified byname. The atom fornamewill be added to window'sWM_PROTOCOLSproperty to tell the window manager that the application has a handler for the protocol specified byname, andcommandwill be invoked in the future whenever the window manager sends a message of that protocol to the Tk application. In this case thewm protocolcommand returns an empty string. - If
nameis specified butcommandis not, then the current handler fornameis returned β or an empty string if there is no handler defined forname. (Special case, don't forget: the default handler forWM_DELETE_WINDOWis not returned. π) - If
commandis specified as an empty string, then the atom fornameis removed from theWM_PROTOCOLSproperty of window and the handler is destroyed; an empty string is returned. - Lastly, if neither
namenorcommandis specified, thewm protocolcommand returns a list of all of the protocols for which handlers are currently defined for window. The full roster. π
wm resizable πΈ
wm resizable window ?width height?
This command controls whether or not the user may interactively resize a top-level window.
If width and height are specified, they're boolean values that determine whether the width and height of window may be modified by the user. In this case the command returns an empty string.
If width and height are omitted, then the command returns a list with two 0/1 elements that indicate whether the width and height of window are currently resizable.
By default, windows are resizable in both dimensions. And if resizing is disabled, then the window's size will be the size from the most recent interactive resize or wm geometry command. If there has been no such operation, then the window's natural size will be used. The window remembers, ok? π§
wm sizefrom β
wm sizefrom window ?who?
If who is specified, it must be either program or user, or an abbreviation of one of these two. It indicates whether window's current size was requested by the program or by the user.
Some window managers ignore program-requested sizes and ask the user to manually size the window; if user is specified then the window manager should give the window its specified size without asking the user for assistance. Respectful. π
- If
whois specified as an empty string, then the current size source is cancelled. - If
whois specified, then the command returns an empty string. - Otherwise it returns
userorwindowto indicate the source of the window's current size β or an empty string if no source has been specified yet.
Most window managers interpret "no source" as equivalent to program. β¨
wm stackorder π
wm stackorder window ?isabove|isbelow window?
The stackorder command returns a list of toplevel windows in stacking order, from lowest to highest. π
When a single toplevel window is passed, the returned list recursively includes all of the window's children that are toplevels. Only those toplevels that are currently mapped to the screen are returned.
The stackorder command can also be used to determine if one toplevel is positioned above or below a second toplevel. When two window arguments separated by either isabove or isbelow are passed, a boolean result indicates whether or not the first window is currently above or below the second window in the stacking order. It's giving "who's standing on whose shoulders" energy. π«Ά
wm state π
wm state window ?newstate?
If newstate is specified, the window will be set to the new state. Otherwise it returns the current state of window: either normal, iconic, withdrawn, icon, or (Windows and macOS only) zoomed.
Now, the difference between iconic and icon, because this trips people up:
iconicrefers to a window that has been iconified (e.g., with thewm iconifycommand).iconrefers to a window whose only purpose is to serve as the icon for some other window (via thewm iconwindowcommand).
π« And no β the icon state cannot be set. Not up for negotiation.
wm title π
wm title window ?string?
If string is specified, then it will be passed to the window manager for use as the title for window β the window manager should display this string in window's title bar. In this case the command returns an empty string.
If string is not specified then the command returns the current title for the window. And the title for a window defaults to its name. So it's never titleless, bestie, it's just wearing its government name until you dress it up. π
wm transient π¦
wm transient window ?container?
If container is specified, then the window manager is informed that window is a transient window (e.g. pull-down menu) working on behalf of container β where container is the path name for a top-level window.
If container is specified as an empty string, then window is marked as not being a transient window any more.
Otherwise the command returns the path name of window's current container, or an empty string if window is not currently a transient window.
A transient window will mirror state changes in the container and inherit the state of the container when initially mapped. So cute, so codependent. π
β οΈ Important: the directed graph with an edge from each transient to its container must be acyclic. In particular, it is an error to attempt to make a window a transient of itself. A window cannot be its own container, that's not self-love that's a stack overflow of the soul. π
The window manager may also decorate a transient window differently, removing some features normally present (e.g., minimize and maximize buttons) β though this is entirely at the discretion of the window manager. No promises.
wm withdraw π
wm withdraw window
Arranges for window to be withdrawn from the screen. This causes the window to be unmapped and forgotten about by the window manager. Gone. Poof. Not ghosting, just withdrawing. β¨
If the window has never been mapped, then this command causes the window to be mapped in the withdrawn state. And lowkey? Not all window managers appear to know how to handle windows that are mapped in the withdrawn state. π
π Also worth knowing: it sometimes seems to be necessary to withdraw a window and then re-map it (e.g. withwm deiconify) to get some window managers to pay attention to changes in window attributes such asgroup. Annoying? Yes. Iconic workaround? Also yes. π
β¨ GEOMETRY MANAGEMENT β¨
Okay so bestie, listen. By default, a top-level window pops onto the screen in its natural size β that's the size determined internally by its widgets and geometry managers. π
If the natural size of a top-level window changes, the window's size changes to match. No cap. π¦
A top-level window can be given a size that is not its natural size in two ways:
- The user can resize the window manually using the facilities of the window manager, such as resize handles. π«Ά
- The application can request a particular size for a top-level window using the
wm geometrycommand. β¨
These two cases are handled identically by Tk; in either case, the requested size overrides the natural size. You can return the window to its natural by invoking wm geometry with an empty geometry string. π
Normally a top-level window can have any size from one pixel in each dimension up to the size of its screen. However, you can use the wm minsize and wm maxsize commands to limit the range of allowable sizes. The range set by wm minsize and wm maxsize applies to all forms of resizing β including the window's natural size, manual resizes, and the wm geometry command. You can use any value accepted by Tk_GetPixels. You can also use the command wm resizable to completely disable interactive resizing in one or both dimensions. π
The wm manage and wm forget commands may be used to perform undocking and docking of windows. After a widget is managed by wm manage, all other wm subcommands may be used with the widget. Only widgets created using the toplevel command may have an attached menu via the -menu configure option. A toplevel widget may be used as a frame and managed with any of the other geometry managers after using the wm forget command. Any menu associated with a toplevel widget will be hidden when managed by another geometry managers. The menus will reappear once the window is managed by wm. All custom bindtags for widgets in a subtree that have their top-level widget changed via a wm manage or wm forget command must be redone to adjust any top-level widget path in the bindtags. Bindtags that have not been customized do not have to be redone. π
πΈ GRIDDED GEOMETRY MANAGEMENT πΈ
Gridded geometry management occurs when one of the widgets of an application supports a range of useful sizes. This happens, for example, in a text editor where the scrollbars, menus, and other adornments are fixed in size but the edit widget can support any number of lines of text or characters per line. π
In this case, it is usually desirable to let the user specify the number of lines or characters-per-line, either with the wm geometry command or by interactively resizing the window. In the case of text, and in other interesting cases also, only discrete sizes of the window make sense, such as integral numbers of lines and characters-per-line; arbitrary pixel sizes are not useful. π
Gridded geometry management provides support for this kind of application. Tk (and the window manager) assume that there is a grid of some sort within the application and that the application should be resized in terms of grid units rather than pixels. β¨
Gridded geometry management is typically invoked by turning on the setGrid option for a widget; it can also be invoked with the wm grid command or by calling Tk_SetGrid. In each of these approaches the particular widget (or sometimes code in the application as a whole) specifies the relationship between integral grid sizes for the window and pixel sizes. To return to non-gridded geometry management, invoke wm grid with empty argument strings. π
When gridded geometry management is enabled then all the dimensions specified in wm minsize, wm maxsize, and wm geometry commands are treated as grid units rather than pixel units. Interactive resizing is also carried out in even numbers of grid units rather than pixels. π
π BUGS π
Lowkey a warning, bestie: most existing window managers appear to have bugs that affect the operation of the wm command. For example, some changes will not take effect if the window is already active: the window will have to be withdrawn and de-iconified in order to make the change happen. π
π EXAMPLES π
A fixed-size window that says that it is fixed-size too:
toplevel .fixed
wm title .fixed "Fixed-size Window"
wm resizable .fixed 0 0
A simple dialog-like window, centred on the screen:
# Create and arrange the dialog contents.
toplevel .msg
label .msg.l -text "This is a very simple dialog demo."
button .msg.ok -text OK -default active -command {destroy .msg}
pack .msg.ok -side bottom -fill x
pack .msg.l -expand 1 -fill both
# Now set the widget up as a centred dialog.
# But first, we need the geometry managers to finish setting
# up the interior of the dialog, for which we need to run the
# event loop with the widget hidden completely...
wm withdraw .msg
update
set x [expr {([winfo screenwidth .] - [winfo width .msg]) / 2}]
set y [expr {([winfo screenheight .] - [winfo height .msg]) / 2}]
wm geometry .msg +$x+$y
wm transient .msg .
wm title .msg "Dialog demo"
wm deiconify .msg
π¦ SEE ALSO π¦
π KEYWORDS π
- aspect ratio
- deiconify
- focus model
- geometry
- grid
- group
- icon
- iconify
- increments
- position
- size
- title
- top-level window
- units
- window manager
And that's the whole page, bestie! π The footer says this is from Tk 8.5, manual section wm(3tk) β source/version locked in. No separate date on this one, but the vibe is timeless. Periodt. π
β¨
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1991-1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms