winfo(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸͺŸ winfo(3tk) β€” Tk Built-In Commands πŸ’–

okay bestie, welcome to the winfo page from the Tk built-in commands manual (winfo(3tk)) β€” this is the one that tells you literally everything about your windows. grab a snack, we're going through all of it. πŸ“βœ¨


✨ NAME ✨

winfo β€” return window-related information πŸͺŸπŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

winfo option ?arg ...?

πŸ’œ DESCRIPTION πŸ’œ

The winfo command is your go-to for pulling info about windows that Tk is managing. it can show up in a bunch of different shapes, depending on what you pass as the option argument. here are all the legal forms, no skips, no cuts, we're doing the whole list 🫢:

  • winfo atom ?-displayof window? name β€” returns a decimal string with the integer identifier for the atom whose name is name. if there's no atom with that name yet, a brand new one gets created (slay, you're a trendsetter). if you pass the -displayof option, the atom gets looked up on the display of window; otherwise it's looked up on the display of the app's main window.
  • winfo atomname ?-displayof window? id β€” returns the textual name for the atom whose integer identifier is id. pass -displayof and 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 one is literally the inverse of the winfo atom command, they're giving opposites attract energy πŸ’ž. it throws 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 with the path names of all the children of window. top-level windows get returned as children of their logical parents. the list comes back in stacking order, lowest window first β€” except for top-level windows, which are not returned in stacking order (rude, honestly). if you wanna know the stacking order of top-level windows, use the wm stackorder command instead. πŸ‘‘
  • winfo class window β€” returns the class name for window.
  • winfo colormapfull window β€” returns 1 if the colormap for window is known to be full, and 0 otherwise. a colormap counts as β€œknown” to be full when the last attempt to allocate a new color on that window failed and this application hasn't freed any colors in the colormap since that failed allocation. so it's like, "as far as we know it's packed to the brim" πŸ’€.
  • 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 in screen units (i.e. any form acceptable to Tk_GetPixels) in the coordinate system of the root window β€” and if a virtual-root window manager is in use, then it's the coordinate system of the virtual root window instead. pass -displayof and the coordinates refer to the screen containing window; otherwise they refer to the screen of the app's main window. if no window in this application contains the point, you get an empty string back. you also get an empty string if the point lies in the title bar or border of its highest containing toplevel in this application. (heads up: with some window managers those borders might be invisible πŸ‘€.) when it's picking the containing window, children get higher priority than parents, and among siblings the highest one in the stacking order wins. main character gets the point, periodt. ✨
  • winfo depth window β€” returns a decimal string giving the depth of window (that's the number of bits per pixel).
  • winfo exists window β€” returns 1 if a window named window exists, 0 if there's no such window. the vibe check command 🫢.
  • winfo fpixels window number β€” returns a floating-point value giving the number of pixels in window that correspond to the distance given by number. number can be in any of the forms acceptable to Tk_GetScreenMM, like 2.0c or 1i. the return value can be fractional β€” if you want an integer, use winfo pixels instead.
  • winfo geometry window β€” returns the geometry for window, in the form widthxheight+x+y. all the dimensions are in pixels. πŸ“
  • winfo height window β€” returns a decimal string giving window's height in pixels. when a window is first created its height is 1 pixel; the height eventually gets changed by a geometry manager to fulfil the window's needs. if you need the true height right 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. (yes this is the "it's 1px and I'm panicking" moment, we've all been there 😭)
  • 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 it's 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 the Tcl interpreters (like, all the Tk-based applications) currently registered for a particular display. pass -displayof and the return value refers to the display of window; otherwise it refers to the display of the application's main window. it's giving "who's online on this display" πŸ¦‹.
  • 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 isn't managed by any geometry manager. the name is usually the name of the Tcl command for that geometry manager, like pack or place. and if the geometry manager is a widget β€” think canvases or text β€” then the name is the widget's class command, like canvas.
  • winfo name window β€” returns window's name (that's its name within its parent, not its full path name). fun fact: winfo name . returns 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 has to be a decimal, hexadecimal, or octal integer, and it has to correspond to a window in the invoking application. pass -displayof and the identifier gets 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 can be in any of the forms acceptable to Tk_GetPixels, like 2.0c or 1i. the result gets 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. and 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: 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. and if the mouse pointer isn't 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. and if the mouse pointer isn't 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 that window's geometry manager uses to compute its geometry.
  • winfo reqwidth window β€” returns a decimal string giving window's requested width, in pixels. this is the value that window's geometry manager uses to compute its geometry. (reqheight and reqwidth are besties, obvi 🫢)
  • winfo rgb window color β€” returns a list with three decimal values in the range 0 to 65535, which are the red, green, and blue intensities corresponding to color in the window given by window. color can be 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 of window itself, 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 of window itself, 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 (that's the 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 these 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.

winfo server window

Okay bestie, so winfo server window is giving you the tea β˜• on the server for window's display. It returns a string with info about that server. The exact format? Honestly it varies from platform to platform, no cap. But for X servers, the string has the form β€œXmajorRminor vendor vendorVersion” β€” wait, let me break it down: major and minor are the version and revision numbers straight from the server (like X11R5 for example), vendor is the name of the vendor running the server, and vendorRelease is an integer release number the server provides. It's giving server lore. πŸ’…

winfo toplevel window

This one returns the path name of the top-of-hierarchy window that contains window. In standard Tk, that's always gonna be a toplevel widget, but bestie, extensions can be extra and create other kinds of top-of-hierarchy widgets. So don't assume, iykyk. πŸ¦‹

winfo viewable window

Returns 1 if window and all its ancestors up through the nearest toplevel window are mapped. Returns 0 if any of these windows are not mapped. It's a vibe check for visibility, fr fr. πŸ‘€

winfo visual window

Returns one of these strings to tell you the visual class for window: directcolor, grayscale, pseudocolor, staticcolor, staticgray, or truecolor. That's the whole list, periodt. 🌈

winfo visualid window

Returns the X identifier for the visual for window. It's giving ID card energy. πŸͺͺ

winfo visualsavailable window ?includeids?

Returns a list where each element describes the visuals available for window's screen. Each element is a visual class followed by an integer depth. The class has the same form as returned by winfo visual. The depth is the number of bits per pixel in the visual. And if you also pass the includeids argument, then the depth is followed by the X identifier for the visual. So you get extra credit info. ✨

winfo vrootheight window

Returns the height of the virtual root window associated with window if there is one; otherwise it returns the height of window's screen. Virtual root? More like virtual slay. πŸ’…

winfo vrootwidth window

Returns the width of the virtual root window associated with window if there is one; otherwise it returns the width of window's screen. Same energy as above but horizontal. ↔️

winfo vrootx window

Returns the x-offset of the virtual root window associated with window, relative to the root window of its screen. This is normally either zero or negative. Returns 0 if there's no virtual root window for window. Offsets can be negative? Not me being shook. 😭

winfo vrooty window

Returns the y-offset of the virtual root window associated with window, relative to the root window of its screen. This is normally either zero or negative. Returns 0 if there's no virtual root window for window. The vertical twin of the last one. ⬆️

winfo width window

Returns a decimal string giving window's width in pixels. When a window is first created, its width will be 1 pixel; the width will eventually be 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. πŸ™ˆ

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 window if it has no border). So it's like, where does this window sit horizontally? πŸ“

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 window if it has no border). The vertical coordinate, bestie. πŸ“


✨ EXAMPLE ✨

Print where the mouse pointer is and what window it is currently over:

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"
}

This little script is iconic. It grabs the pointer coords, then finds the window containing them, and prints it. If there's no window, it says "over no window". Chef's kiss. πŸ‘‘


πŸ”‘ KEYWORDS πŸ”‘

atom, children, class, geometry, height, identifier, information, interpreters, mapped, parent, path name, screen, virtual root, width, window


That's the whole vibe, bestie. This page is from Tk version 4.3, and it's the winfo(3tk) manual page. Stay slaying with your windows. πŸ’–βœ¨

πŸ“¦ where this page comes from