winfo(n)
π winfo(n) β Tk Built-In Commands πͺ
okay bestie, sit down, because this one is a whole saga. this is winfo from the Tk Built-In Commands manual, and it's basically the plugin that lets you peek at literally everything Tk knows about your windows. no cap. π«Ά
β¨ NAME β¨
winfo β returns window-related information, aka the group chat receipts for every window Tk is managing π
πΈ SYNOPSIS πΈ
winfo option ?arg ...?
π¦ DESCRIPTION π¦
so like, the winfo command is the way to retrieve information about windows that Tk manages. it's giving detective energy π β you ask it a question and it comes back with the tea. it can take any of a number of different forms, depending on the option argument. here are all the legal forms, and yes, we're doing all of them, because we don't skip π
winfo atom ?-displayof window? nameβ returns a decimal string giving the integer identifier for the atom whose name is name. if no atom exists with the name name, then a new one is created (iconic, it just spawns one for you β¨). if the-displayofoption is given, then the atom is looked up on the display of window; otherwise it's looked up on the display of the application's main window.winfo atomname ?-displayof window? idβ returns the textual name for the atom whose integer identifier is id. if-displayofis given, the identifier is looked up on the display of window; otherwise it's looked up on the display of the application's main window. this command is the inverse of thewinfo atomcommand π. heads up: it generates an error if no such atom exists π.winfo cells windowβ returns a decimal string giving the number of cells in the color map for window. π¨winfo children windowβ returns a list containing the path names of all the children of window. top-level windows are returned as children of their logical parents. the list is in stacking order, with the lowest window first β except for top-level windows, which are not returned in stacking order. use thewm stackordercommand to query the stacking order of top-level windows π.winfo class windowβ returns the class name for window. π·οΈwinfo colormapfull windowβ returns1if the colormap for window is known to be full,0otherwise. and "known" is doing a lot of work here: the colormap is "known" to be full if the last attempt to allocate a new color on that window failed and this application has not freed any colors in the colormap since the failed allocation. so it's a vibes-based flag, basically πwinfo containing ?-displayof window? rootX rootYβ returns the path name for the window containing the point given by rootX and rootY. rootX and rootY are specified in screen units (i.e. any form acceptable toTk_GetPixels) in the coordinate system of the root window (if a virtual-root window manager is in use then the coordinate system of the virtual root window is used). if-displayofis given, the coordinates refer to the screen containing window; otherwise they refer to the screen of the application's main window. if no window in this application contains the point, then an empty string is returned. an empty string is also returned if the point lies in the title bar or border of its highest containing toplevel in this application (note that with some window managers the borders may be invisible π). in selecting the containing window, children are given higher priority than parents, and among siblings the highest one in the stacking order is chosen. main character energy for whoever's on top, fr fr πwinfo depth windowβ returns a decimal string giving the depth of window (number of bits per pixel). πΌοΈwinfo exists windowβ returns1if there exists a window named window,0if no such window exists. the vibe check command, basically βwinfo fpixels window numberβ returns a floating-point value giving the number of pixels in window corresponding to the distance given by number. number may be specified in any of the forms acceptable toTk_GetScreenMM, such as2.0cor1i. the return value may be fractional; for an integer value, usewinfo pixelsπ’.winfo geometry windowβ returns the geometry for window, in the formwidthxheight+x+y. all dimensions are in pixels π.winfo height windowβ returns a decimal string giving window's height in pixels. okay so real talk: when a window is first created its height will be1pixel β tiny! the height will eventually be changed by a geometry manager to fulfil the window's needs. if you need the true height immediately after creating a widget, invokeupdateto force the geometry manager to arrange it, or usewinfo reqheightto get the window's requested height instead of its actual height. don't get caught lacking by the 1-pixel era ππwinfo id windowβ returns a hexadecimal string giving a low-level platform-specific identifier for window. on Unix platforms, this is the X window identifier. under Windows, this is the WindowsHWND. on the Macintosh the value has no meaning outside Tk πͺͺ.winfo interps ?-displayof window?β returns a list whose members are the names of all Tcl interpreters (e.g. all Tk-based applications) currently registered for a particular display. if-displayofis given, the return value refers to the display of window; otherwise it refers to the display of the application's main window. it's the "who else is at this party" command π.winfo ismapped windowβ returns1if window is currently mapped,0otherwise πΊοΈ.winfo manager windowβ returns the name of the geometry manager currently responsible for window, or an empty string if window is not managed by any geometry manager. the name is usually the name of the Tcl command for the geometry manager, such aspackorplace. if the geometry manager is a widget, such as canvases or text, the name is the widget's class command, such ascanvasπ§βπ³ (someone's gotta plate this window).winfo name windowβ returns window's name (i.e. its name within its parent, as opposed to its full path name). the commandwinfo name .will return the name of the application π .winfo parent windowβ returns the path name of window's parent, or an empty string if window is the main window of the application π¨βπ§.winfo pathname ?-displayof window? idβ returns the path name of the window whose X identifier is id. id must be a decimal, hexadecimal, or octal integer and must correspond to a window in the invoking application. if-displayofis given, the identifier is looked up on the display of window; otherwise it's looked up on the display of the application's main window π§.winfo pixels window numberβ returns the number of pixels in window corresponding to the distance given by number. number may be specified in any of the forms acceptable toTk_GetPixels, such as2.0cor1i. the result is rounded to the nearest integer value; for a fractional result, usewinfo fpixelsπ’β¨.winfo pointerx windowβ if the mouse pointer is on the same screen as window, returns the pointer's x coordinate, measured in pixels in the screen's root window. if a virtual root window is in use on the screen, the position is measured in the virtual root. if the mouse pointer is not on the same screen as window, then-1is returned π±οΈ.winfo pointerxy windowβ if the mouse pointer is on the same screen as window, returns a list with two elements, which are the pointer's x and y coordinates measured in pixels in the screen's root window. if a virtual root window is in use on the screen, the position is computed in the virtual root. if the mouse pointer is not on the same screen as window, then both of the returned coordinates are-1ππ±οΈ.winfo pointery windowβ if the mouse pointer is on the same screen as window, returns the pointer's y coordinate, measured in pixels in the screen's root window. if a virtual root window is in use on the screen, the position is computed in the virtual root. if the mouse pointer is not on the same screen as window, then-1is returned π±οΈ.winfo reqheight windowβ returns a decimal string giving window's requested height, in pixels. this is the value used by window's geometry manager to compute its geometry πββοΈ (it's what the window wants, not what it got).winfo reqwidth windowβ returns a decimal string giving window's requested width, in pixels. this is the value used by window's geometry manager to compute its geometry πββοΈ.winfo rgb window colorβ returns a list containing three decimal values in the range0to65535, which are the red, green, and blue intensities that correspond to color in the window given by window. color may be specified in any of the forms acceptable for acoloroption π.winfo rootx windowβ returns a decimal string giving the x-coordinate, in the root window of the screen, of the upper-left corner of window's border (or window if it has no border) π.winfo rooty windowβ returns a decimal string giving the y-coordinate, in the root window of the screen, of the upper-left corner of window's border (or window if it has no border) π.winfo screen windowβ returns the name of the screen associated with window, in the formdisplayName.screenIndexπ₯οΈ.winfo screencells windowβ returns a decimal string giving the number of cells in the default color map for window's screen π¨.winfo screendepth windowβ returns a decimal string giving the depth of the root window of window's screen (number of bits per pixel) π.winfo screenheight windowβ returns a decimal string giving the height of window's screen, in pixels π.winfo screenmmheight windowβ returns a decimal string giving the height of window's screen, in millimeters ππΈ.winfo screenmmwidth windowβ returns a decimal string giving the width of window's screen, in millimeters ππΈ.winfo screenvisual windowβ returns one of the following strings to indicate the default visual class for window's screen:directcolor,grayscale,pseudocolor,staticcolor,staticgray, ortruecolorποΈπ.winfo screenwidth windowβ returns a decimal string giving the width of window's screen, in pixels π.
okay and that's not even the whole list, bestie β there's more coming in part 2, so don't close the tab π€
winfo serverwindow β bestie, this one spills the tea about the server backing window's display β It hands back a string, and the exact format is a whole "depends on the platform" situation. For X servers it looks like βXmajorRminor vendor vendorVersionβ β where major and minor are the version and revision numbers the server provides (thinkX11R5), vendor is the server's vendor name, and vendorRelease is an integer release number the server provides. β¨winfo toplevelwindow β returns the path name of the top-of-hierarchy window that contains window. In standard Tk that's always a toplevel widget, but extensions are allowed to cook up other kinds of top-of-hierarchy widgets. iykyk π«Άwinfo viewablewindow β returns1if window and every single one of its ancestors, all the way up through the nearest toplevel window, are mapped π Returns0if any of those windows are not mapped. no in-betweens, periodt.winfo visualwindow β returns one of these strings to tell you the visual class for window:directcolor,grayscale,pseudocolor,staticcolor,staticgray, ortruecolor. pick your fighter πwinfo visualidwindow β returns the X identifier for the visual of window. the β¨actual IDβ¨, not just the class.winfo visualsavailablewindow ?includeids? β returns a list where each element describes a visual available for window's screen π Each element is a visual class followed by an integer depth. The class is in the same form thatwinfo visualreturns. The depth is the number of bits per pixel in that visual. Bonus round: if you pass the includeids argument, then the depth gets followed by the X identifier for the visual. πwinfo vrootheightwindow β returns the height of the virtual root window associated with window, if there even is one; otherwise it gives you the height of window's screen. either way you're covered π¦winfo vrootwidthwindow β same deal, horizontal edition: returns the width of the virtual root window associated with window if one exists; otherwise, the width of window's screen. πΈwinfo vrootxwindow β returns the x-offset of the virtual root window associated with window, relative to the root window of its screen. Normally this is either zero or negative, ngl. Returns0if there's no virtual root window for window.winfo vrootywindow β the y-offset version π offset of the virtual root window associated with window, relative to the root window of its screen. Normally either zero or negative. Returns0if there's no virtual root window for window.winfo widthwindow β returns a decimal string with window's width in pixels. π Here's the lore: when a window is first created its width will be1pixel, and the width eventually gets changed by a geometry manager to fulfil the window's needs. So if you need the true width immediately after creating a widget, invokeupdateto force the geometry manager to arrange it β or usewinfo reqwidthto get the window's requested width instead of its actual width. don't get caught lacking πwinfo xwindow β returns a decimal string giving the x-coordinate, in window's parent, of the upper-left corner of window's border (or of window itself if it has no border). πwinfo ywindow β returns a decimal string giving the y-coordinate, in window's parent, of the upper-left corner of window's border (or of window itself if it has no border). π
π EXAMPLE π
Print where the mouse pointer is and what window it is currently over β honestly iconic behaviour:
lassign [winfo pointerxy .] x y
puts -nonewline "Mouse pointer at ($x,$y) which is "
set win [winfo containing $x $y]
if {$win eq ""} {
puts "over no window"
} else {
puts "over $win"
}
π KEYWORDS π
atom, children, class, geometry, height, identifier, information, interpreters, mapped, parent, path name, screen, virtual root, width, window
And that's the whole vibe check, bestie β you made it to the end π«Άβ¨ This page is from Tk 4.3, dated 4.3, and it's section n of the manual, filed under the name winfo(n). Go forth and query windows, you absolute icon ππ
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- Copyright (c) 1990-1994 The Regents of the University of California
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms