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 -displayof option 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 -displayof is 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 the winfo atom command πŸ”. 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 the wm stackorder command to query the stacking order of top-level windows πŸ‘€.
  • winfo class window β€” returns the class name for window. 🏷️
  • winfo colormapfull window β€” returns 1 if the colormap for window is known to be full, 0 otherwise. 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 to Tk_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 -displayof is 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 β€” returns 1 if there exists a window named window, 0 if 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 to Tk_GetScreenMM, such as 2.0c or 1i. the return value may be fractional; for an integer value, use winfo pixels πŸ”’.
  • winfo geometry window β€” returns the geometry for window, in the form widthxheight+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 be 1 pixel β€” 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, invoke update to force the geometry manager to arrange it, or use winfo reqheight to 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 Windows HWND. 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 -displayof is 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 β€” returns 1 if window is currently mapped, 0 otherwise πŸ—ΊοΈ.
  • 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 as pack or place. if the geometry manager is a widget, such as canvases or text, the name is the widget's class command, such as canvas πŸ§‘β€πŸ³ (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 command winfo 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 -displayof is 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 to Tk_GetPixels, such as 2.0c or 1i. the result is rounded to the nearest integer value; for a fractional result, use winfo 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 -1 is 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 -1 is 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 range 0 to 65535, 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 a color option 🌈.
  • 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 form displayName.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, or truecolor πŸ‘οΈπŸŒˆ.
  • 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 server window β€” 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 (think X11R5), vendor is the server's vendor name, and vendorRelease is an integer release number the server provides. ✨
  • winfo toplevel window β€” 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 viewable window β€” returns 1 if window and every single one of its ancestors, all the way up through the nearest toplevel window, are mapped πŸ’… Returns 0 if any of those windows are not mapped. no in-betweens, periodt.
  • winfo visual window β€” returns one of these strings to tell you the visual class for window: directcolor, grayscale, pseudocolor, staticcolor, staticgray, or truecolor. pick your fighter 🌈
  • winfo visualid window β€” returns the X identifier for the visual of window. the ✨actual ID✨, not just the class.
  • winfo visualsavailable window ?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 that winfo visual returns. 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 vrootheight window β€” 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 vrootwidth window β€” 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 vrootx window β€” 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. Returns 0 if there's no virtual root window for window.
  • winfo vrooty window β€” 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. Returns 0 if there's no virtual root window for window.
  • winfo width window β€” returns a decimal string with window's width in pixels. πŸŽ€ Here's the lore: when a window is first created its width will be 1 pixel, 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, invoke update to force the geometry manager to arrange it β€” or use winfo reqwidth to get the window's requested width instead of its actual width. don't get caught lacking πŸ™ˆ
  • winfo x window β€” 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 y window β€” 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