wtext

The wtext object (widget text) is often used together with widgets such as sliders. It provides a way to modify dynamically a portion of the title or caption of a canvas, perhaps in response to user interactions or computed changes.

The example program ButtonsMenusSliders uses wtext to display the current rotation speed of a cube whose rotation is controlled by a slider.

Variables must be converted to a string using standard Python formatting options. Text may be updated any time by setting the text attribute of the wtext object:

myspeedtxt.text = f'omega = {vslider.value:.1e} radians/s'

Accessibility Attributes

aria_hidden (boolean)

If True, the wtext element is hidden from screen readers. Use for decorative or redundant text that should not be announced:

units_label = wtext(text=" radians/s", aria_hidden=True)
aria_live (string)

When set, a screen reader will announce the wtext content whenever it changes. Values are 'polite' (announces when the user is idle) or 'assertive' (announces immediately, interrupting other speech). Use 'polite' for most dynamic readouts:

speedtxt = wtext(text="Speed: 5", aria_live='polite')

A wtext with aria_live can also be used as the aria_labelledby or aria_describedby target of a widget — the screen reader will announce label changes whenever the text updates.

See also aria_div for grouping multiple widgets into a single live region.