Winfo
This capability documents one focused aspect of the widget interface (Tk/Tcl-style behavior + bootstack extensions).
Note: You typically won’t use
bootstack.core.capabilities.winfodirectly. This page describes the behavior that widgets expose.
Widget information (winfo) helpers.
Tk uses the term window to mean any widget with a Tk window handle
(not just a Toplevel). In bootstack documentation we use the word
widget unless we specifically mean a top-level window.
Tk's winfo command family exposes runtime information about a widget/window:
geometry, hierarchy, mapping/visibility, pointer location, screen metrics, and more.
This mixin provides thin pass-through methods with modern Google-style
docstrings for commonly used winfo_* APIs in Tkinter.
Intended usage
class Widget(WinfoMixin, ttk.Widget): ... class App(WinfoMixin, tkinter.Tk): ... class Window(WinfoMixin, tkinter.Toplevel): ...
Notes
- All methods delegate to the underlying Tkinter implementation.
- Many
winfo_*values are only meaningful after the widget has been realized and geometry has been computed. If you need up-to-date sizes, callupdate_idletasks()first.
winfo_exists
winfo_exists() -> int
Return whether this widget exists.
Returns:
| Type | Description |
|---|---|
int
|
1 if the widget exists, 0 otherwise. |
winfo_ismapped
winfo_ismapped() -> int
Return whether this widget is currently mapped (shown) on screen.
A widget may exist but not be mapped (e.g., never packed/gridded/placed, or explicitly unmapped).
Returns:
| Type | Description |
|---|---|
int
|
1 if mapped, 0 otherwise. |
winfo_viewable
winfo_viewable() -> int
Return whether this widget and all its ancestors are mapped.
A widget can be mapped but not viewable if an ancestor is not mapped.
Returns:
| Type | Description |
|---|---|
int
|
1 if viewable, 0 otherwise. |
winfo_id
winfo_id() -> int
Return a platform-specific identifier for the underlying window.
Returns:
| Type | Description |
|---|---|
int
|
An integer window identifier. Meaning varies by platform. |
winfo_name
winfo_name() -> str
Return the widget's Tk name (path component, not full path).
Returns:
| Type | Description |
|---|---|
str
|
The widget's name (e.g. "button", "frame", etc.). |
winfo_pathname
winfo_pathname(
id: int, displayof: int | None = None
) -> str
Return the Tk pathname for a window id.
This is an advanced helper; most apps won't need it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
A platform-specific window id (often from |
required |
displayof
|
int | None
|
Optional display selector (Tk-specific). Rarely needed. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The Tk pathname corresponding to |
winfo_parent
winfo_parent() -> str
Return the Tk pathname of this widget's parent.
Returns:
| Type | Description |
|---|---|
str
|
The parent's Tk pathname. |
winfo_toplevel
winfo_toplevel() -> Any
Return the toplevel window that contains this widget.
Returns:
| Type | Description |
|---|---|
Any
|
The toplevel widget instance. |
winfo_children
winfo_children() -> list[Any]
Return this widget's direct children.
Returns:
| Type | Description |
|---|---|
list[Any]
|
A list of child widget instances. |
winfo_class
winfo_class() -> str
Return the Tk class name for this widget (e.g. 'TButton').
Returns:
| Type | Description |
|---|---|
str
|
The Tk class name string. |
winfo_manager
winfo_manager() -> str
Return the geometry manager controlling this widget.
Typical values are: "pack", "grid", "place", or "" if unmanaged.
Returns:
| Type | Description |
|---|---|
str
|
The name of the geometry manager or an empty string. |
winfo_x
winfo_x() -> int
Return the x-coordinate of this widget relative to its parent.
Returns:
| Type | Description |
|---|---|
int
|
The x position in pixels. |
winfo_y
winfo_y() -> int
Return the y-coordinate of this widget relative to its parent.
Returns:
| Type | Description |
|---|---|
int
|
The y position in pixels. |
winfo_width
winfo_width() -> int
Return the current width of this widget in pixels.
Note
Geometry may be stale until Tk processes idle tasks. Use
update_idletasks() if you need a fresh value.
Returns:
| Type | Description |
|---|---|
int
|
The width in pixels. |
winfo_height
winfo_height() -> int
Return the current height of this widget in pixels.
Note
Geometry may be stale until Tk processes idle tasks. Use
update_idletasks() if you need a fresh value.
Returns:
| Type | Description |
|---|---|
int
|
The height in pixels. |
winfo_reqwidth
winfo_reqwidth() -> int
Return the requested width (geometry request) in pixels.
This is the size the widget asks for before geometry management.
Returns:
| Type | Description |
|---|---|
int
|
The requested width in pixels. |
winfo_reqheight
winfo_reqheight() -> int
Return the requested height (geometry request) in pixels.
This is the size the widget asks for before geometry management.
Returns:
| Type | Description |
|---|---|
int
|
The requested height in pixels. |
winfo_rootx
winfo_rootx() -> int
Return the absolute x-coordinate of this widget on the screen.
Returns:
| Type | Description |
|---|---|
int
|
The screen x position in pixels. |
winfo_rooty
winfo_rooty() -> int
Return the absolute y-coordinate of this widget on the screen.
Returns:
| Type | Description |
|---|---|
int
|
The screen y position in pixels. |
winfo_pointerx
winfo_pointerx() -> int
Return the pointer x-coordinate on the screen.
This returns the mouse pointer position in screen (root) coordinates.
Returns:
| Type | Description |
|---|---|
int
|
The screen x position of the pointer in pixels. |
winfo_pointery
winfo_pointery() -> int
Return the pointer y-coordinate on the screen.
This returns the mouse pointer position in screen (root) coordinates.
Returns:
| Type | Description |
|---|---|
int
|
The screen y position of the pointer in pixels. |
winfo_pointerxy
winfo_pointerxy() -> tuple[int, int]
Return the pointer (x, y) coordinates on the screen.
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
A tuple (x, y) in screen (root) coordinates. |
winfo_containing
winfo_containing(rootx: int, rooty: int) -> Any
Return the widget that contains the given screen coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rootx
|
int
|
Screen x coordinate in pixels. |
required |
rooty
|
int
|
Screen y coordinate in pixels. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The widget instance at that screen coordinate, or None if no widget |
Any
|
is present at that location. |
winfo_screenwidth
winfo_screenwidth() -> int
Return the width of the screen in pixels.
Returns:
| Type | Description |
|---|---|
int
|
Screen width in pixels. |
winfo_screenheight
winfo_screenheight() -> int
Return the height of the screen in pixels.
Returns:
| Type | Description |
|---|---|
int
|
Screen height in pixels. |
winfo_fpixels
winfo_fpixels(number: str) -> float
Convert a distance string to pixels (floating point).
Tk distance strings can include units like
- "c" (centimeters)
- "i" (inches)
- "m" (millimeters)
- "p" (points)
Plain numbers are pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
A Tk distance string (e.g. "2c", "0.5i", "10"). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The distance in pixels as a float. |
winfo_pixels
winfo_pixels(number: str) -> int
Convert a distance string to pixels (integer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
A Tk distance string (e.g. "2c", "0.5i", "10"). |
required |
Returns:
| Type | Description |
|---|---|
int
|
The distance in pixels as an int (rounded by Tk). |