Difference between revisions of "LuaAPI/types/widget"

From The Battle for Wesnoth Wiki
< LuaAPI‎ | types
(unfolded is actually in 1.18)
 
(41 intermediate revisions by 6 users not shown)
Line 1: Line 1:
the 'widget' userdata offers access to a widget of a gui2 dialog, while there is only one type of widget userdata that covers all widgets including the window itself, The properties of a widget userdataq are different for each widgets. Indexing a widgets userdata can either be used to
+
<div class="tright"> __TOC__ </div>
  
* Access a child widget
+
The '''widget''' userdata offers access to a widget of a GUI2 dialog. While there is only one type of widget userdata that covers all widgets including the window itself, the properties of a widget userdata are different for each type of widget. Indexing a widget's userdata can either be used to access a child widget or to set or get a property of a widget. Some properties are read-only or write-only; the properties depend on the type of the widget.
Example code
+
 
```
+
An example of accessing a child widget:
 +
 
 +
<syntaxhighlight lang=lua>
 
function preshow(dialog)
 
function preshow(dialog)
 
   local okay_button = dialog.okay_button
 
   local okay_button = dialog.okay_button
   -- okay_button is now a handle to the the widgets child with the id 'okay_button'  
+
   -- okay_button is now a handle to the the widget's child with the id 'okay_button'  
 
end
 
end
``` or to  
+
</syntaxhighlight>
* Set/Get a property of a widget Some Properties are read-only, the propertied depends on the type of the widget, the following properties exist:
+
 
 +
{{DevFeature1.19|x}} Some fields are only available in newer versions of Wesnoth. However, even in this case it might be possible to set the attribute in question before the dialog is first shown by adjusting its definition WML accordingly. See [[GUIWidgetInstanceWML]] for more information on WML attributes available for each widget class.
 +
 
 +
== Widget Attributes ==
 +
 
 +
=== best_slider_length ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''best_slider_length''' &harr; ''length''
 +
* Available on: '''[slider]'''
 +
Best length of the slider.
 +
 
 +
=== characters_per_line ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''label''' &harr; ''int''
 +
* Available on: '''[label]'''
 +
Maximum characters this label should show per line.
 +
 
 +
=== editable ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''enabled''' &harr; ''boolean''
 +
* Available on: '''[text_box]'''
 +
If this text box is editable, i.e., read-only. (Text can be selected/copied but not modified.)
 +
 
 +
=== ellipsize_mode ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''ellipsize_mode''' &harr; ''ellipsization mode string''
 +
* Available on: Most widgets
 +
Sets the [https://docs.gtk.org/Pango/enum.EllipsizeMode.html Pango ellipsization mode] for the widget. Accepts only one of the special strings:
 +
{| clasS="wikitable"
 +
! String value
 +
|-
 +
| none
 +
|-
 +
| start
 +
|-
 +
| end
 +
|-
 +
| middle
 +
|-
 +
|}
 +
 
 +
=== enabled ===
 +
* ''widget''.'''enabled''' &harr; ''boolean''
 +
* Available on: Most widgets
 +
 
 +
=== help ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''enabled''' &harr; ''text''
 +
* Available on: Most widgets
 +
Help text for this widget.
  
 +
=== hint_image ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''hint_image''' &harr; ''text''
 +
* Available on: '''[text_box]''', '''[combobox]'''
 +
A image that is shown on the widget when it is not focused and has no other text.
  
=== widget attributes ===
+
=== hint_text ===
==== selected ====
+
{{DevFeature1.19|6}}
* '''w.selected = value'''
+
* ''widget''.'''hint_text''' &harr; ''text''
* '''boolean'''
+
* Available on: '''[text_box]''', '''[combobox]'''
* '''get/set'''
+
A background text that is shown on the widget when it is not focused and has no other text.
* [toggle_button], [toggle_panel]
+
 
whether the item is selected or not
+
=== history ===
==== selected_index ====
+
{{DevFeature1.19|6}}
* '''w.selected_index = value'''
+
* ''widget''.'''history''' &larr; ''text''
* '''number'''
+
* Available on: '''[text_box]'''
* '''get/set'''
+
Input history of this text box.
* [listbox], [multi_page], [stacked_widget], selectable_item ([menu_button], [toggle_button], [toggle_panel])
+
 
the selected index of the item
+
=== indentation_step_size ===
==== text ====
+
{{DevFeature1.19|6}}
* '''w.text = value'''
+
* ''widget''.'''indentation_step_size''' &harr; ''int''
* '''string'''
+
* Available on: '''[tree_view]'''
* '''get/set'''
+
How much should child nodes be offset from their parent node.
* [text_box]
+
 
the text of the textbox
+
=== item_count ===
==== value ====
+
{{DevFeature1.19|6}}
* '''w.value = value'''
+
* ''widget''.'''item_count''' &rarr; ''number of items''
* '''number'''
+
* Available on: '''[multi_page]''', '''[listbox]''',  '''[combobox]''',  '''[stacked_widget]''', '''[tree_view]''',  '''[tree_view_node]''', '''[styled_widget]'''
* '''get/set'''
+
The number of items in the container widget.
* [slider]
+
 
==== percentage ====
+
=== label ===
* '''w.percentage = value'''
+
* ''widget''.'''label''' &larr; ''text''
* '''number'''
+
* Available on: Most widgets, in particular '''[label]''', '''[button]''', '''[image]'''
* '''get/set'''
+
The widget's label. Technically this is a special string used in the widget's wml definition. It usually does what one would expect, but also sets the image for '''image''' widgets.  For '''[text_box]''', use '''text''' for initial values.
* [progress_bar]
+
 
==== selected_item_path ====
+
=== link_aware ===
* '''value = w.selected_item_path'''
+
{{DevFeature1.19|6}}
* '''array of integers'''
+
* ''widget''.'''link_aware''' &rarr; ''boolean''
* '''get'''
+
* Available on: '''[label]''', '''[rich_label]''', '''[scroll_label]''', '''[scroll_text]'''
* [slider]
+
Whether this widget recognizes inline links and allows clicking on them.
a table descibing the currently selected node. If for example in this treeview
+
 
 +
=== link_color ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''link_color''' &rarr; ''color string''
 +
* Available on: '''[label]''', '''[rich_label]'''
 +
Color of the inline link, as an hex string.
 +
 
 +
=== marked_up_text ===
 +
* ''widget''.'''marked_up_text''' &larr; ''text''
 +
* Available on: Most widgets, in particular '''[label]''', '''[button]'''
 +
Shortcut for setting label and use_markup=yes.
 +
 
 +
=== maximum_value_label ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''maximum_value_label''' &harr; ''text''
 +
* Available on: '''[slider]'''
 +
The text the slider's label shows when it is at maximum value position.
 +
 
 +
=== max_input_length ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''max_input_length''' &harr; ''text''
 +
* Available on: '''[text_box]''', '''[combobox]'''
 +
Maximum number of character than can be input into this widget.
 +
 
 +
=== minimum_value_label ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''minimum_value_label''' &harr; ''text''
 +
* Available on: '''[slider]'''
 +
The text the slider's label shows when it is at minimum value position.
 +
 
 +
=== overflow_to_tooltip ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''overflow_to_tooltip''' &harr; ''boolean''
 +
* Available on: Most widgets
 +
 
 +
=== path ===
 +
* ''widget''.'''path''' &rarr; ''array of indices''
 +
* Available on: '''[tree_view_node]'''
 +
A table describing this node in the overall treeview. See [[#selected_item_path|selected_item_path]] for the meaning of the table..
 +
 
 +
=== percentage ===
 +
* ''widget''.'''percentage''' &harr; ''position''
 +
* Available on: '''[progress_bar]'''
 +
The current position of the progress bar, between 0 and 100.
 +
 
 +
=== selected ===
 +
* ''widget''.'''selected''' &harr; ''boolean''
 +
* Available on: '''[toggle_button]''', '''[toggle_panel]'''
 +
Whether the item is selected or not. Note that this should only be used for widgets that have only 2 states. In particular, there exist 3-State toggle_buttons (for example in listbox headers). For those, selected_index must be used instead.
 +
 
 +
=== selected_index ===
 +
* ''widget''.'''selected_index''' &harr; ''index''
 +
* Available on: '''[listbox]''', '''[multi_page]''', '''[stacked_widget]''', '''[menu_button]''', '''[toggle_button]''', '''[toggle_panel]'''
 +
The selected index of the item. For '''[toggle_button]''' and '''[toggle_panel]''', this is the same as '''selected''' only encoded as a number (1 for false or 2 for true) instead of a boolean.
 +
For a  '''[listbox]'''with '''has_maximum=false''' and more than one item selected, reading '''selected_index''' will return the first selected index.
 +
For a '''[stacked_widget]''', only the layer specified by '''selected_index''' will be displayed and receive events (callbacks will only be triggered on the selected layer).
 +
A '''selected_index''' of 0 represents all layers being selected, with events only being received by the layer with the highest index.  Note that term ''selected'' for the ''layer'' of a stacked_widget is not the same as the '''selected''' ''widget'' attribute.
 +
 
 +
=== selected_item_path ===
 +
* ''widget''.'''selected_item_path''' &rarr; ''array of indices''
 +
* Available on: '''[tree_view]'''
 +
A table describing the currently selected node. If for example, in the following treeview, Item 9 is selected, the result will be {2,1,3}.
 
  +Section1
 
  +Section1
 
   +Subsection11
 
   +Subsection11
Line 65: Line 182:
 
   *Item11
 
   *Item11
 
   *Item12
 
   *Item12
Item 9 is selected the value will be {2,1,3}
+
 
==== path ====
+
=== step_size ===
* '''value = w.path'''
+
{{DevFeature1.19|6}}
* '''array of integers'''
+
* ''widget''.'''step_size''' &harr; ''int''
* '''get'''
+
* Available on: '''[slider]'''
* [tree_view_node]
+
 
See selected_item_path for the syntax.
+
=== text ===
==== unfolded ====
+
* ''widget''.'''text''' &harr; ''text''
* '''w.unfolded = value'''
+
* Available on: '''[text_box]'''
* '''boolean'''
+
The text of the textbox.
* '''set'''
+
 
* [tree_view_node]
+
=== text_alignment ===
==== unit ====
+
{{DevFeature1.19|6}}
* '''w.unit = value'''
+
* ''widget''.'''text_alignment''' &harr; ''text alignment string''
* '''unit''' or '''unit type'''
+
* Available on: Most widgets
* '''set'''
+
Sets the [https://docs.gtk.org/Pango/enum.Alignment.html Pango text alignment] for the widget. Accepts only one of the special strings:
* [unit_preview_pane]
+
{| clasS="wikitable"
==== item_count ====
+
! String value
* '''value = w.item_count'''
+
|-
* '''number'''
+
| left
* '''get'''
+
|-
* [multi_page], [listbox]
+
| right
==== use_markup ====
+
|-
* '''w.use_markup = value'''
+
| center
* '''boolean'''
+
|-
* '''set'''
+
|}
* most widgets, in particular [label], [button]
+
 
==== label ====
+
=== tooltip ===
* '''w.label = value'''
+
* ''widget''.'''tooltip''' &harr; ''text''
* '''string'''
+
* Available on: Most widgets
* '''set'''
+
 
* most widgets, in particular [label], [button], [image]
+
=== type ===
the label, technically the is a special string used in the widgets wml definition, it usualyl does what one would expect but also sets the image for [image] widgets
+
* ''widget''.'''type''' &rarr; ''string''
==== marked_up_text ====
+
* Available on: All widgets
* '''w.marked_up_text = value'''
+
Returns a string specifying the type of the widget.
* '''string'''
+
 
* '''set'''
+
=== unfolded ===
* most widgets, in particular [label], [button]
+
* ''widget''.'''unfolded''' &larr; ''boolean''
shortcut for setting label and use_markup=yes
+
* Available on: '''[tree_view_node]''', '''[tree_view]'''
==== enabled ====
+
Control whether a tree node is currently expanded or not.
* '''w.enabled = value'''
+
 
* '''boolean'''
+
=== unit ===
* '''set'''
+
* ''widget''.'''unit''' &larr; ''unit or unit type''
* all widgets
+
* Available on: '''[unit_preview_pane]'''
==== tooltip ====
+
Change the displayed unit or unit type in the preview pane.
* '''w.tooltip = value'''
+
 
* '''string'''
+
=== use_markup ===
* '''set'''
+
* ''widget''.'''use_markup''' &rarr; ''boolean''
* all widgets
+
* Available on: Most widgets, in particular '''[label]''', '''[button]'''
==== visible ====
+
Sets whether the widget's label will parse [[Pango formatting]].
* '''w.visible = value'''
+
 
* '''string'''
+
=== value ===
* '''set'''
+
* ''widget''.'''value''' &harr; ''position''
* all widgets
+
* Available on: '''[slider]'''
The following visibility statuses are recognized:
+
The current position of the slider.
 +
 
 +
=== visible ===
 +
* ''widget''.'''visible''' &harr; ''visibility string''
 +
* Available on: Most widgets
 +
Determines whether the widget is visible onscreen. The following visibility statuses are recognized:
 
{| clasS="wikitable"
 
{| clasS="wikitable"
 
! String value !! Boolean shorthand !! Meaning
 
! String value !! Boolean shorthand !! Meaning
Line 129: Line 251:
 
| invisible || false || The widget is not visible, doesn't handle events, and does not take up space on the dialog grid.
 
| invisible || false || The widget is not visible, doesn't handle events, and does not take up space on the dialog grid.
 
|}
 
|}
==== type ====
 
* '''value = w.type'''
 
* '''string'''
 
* '''get'''
 
* all widgets
 
=== widget callbacks ===
 
==== on_modified ====
 
* '''function w.on_modified() .... end
 
* all widgets the allow the user to select a value of any type.
 
==== on_left_click ====
 
* '''function w.on_left_click() .... end
 
* all widgets
 
==== on_button_click ====
 
* '''function w.on_button_click() .... end
 
* button type widgets
 
  
=== widget methods ===
+
=== wrap ===
 +
{{DevFeature1.19|6}}
 +
* ''widget''.'''wrap''' &rarr; ''boolean''
 +
* Available on: '''[label]'''
 +
Whether the text content in this label can wrap.
 +
 
 +
== Widget Callbacks ==
 +
 
 +
=== on_button_click ===
 +
 
 +
* ''widget''.'''on_button_click''' &larr; '''function'''()
 +
* Available on: '''[button]''', '''[repeating_button]'''
 +
 
 +
Triggers when the user clicks on the button. This can differ from '''on_left_click''', depending on the type of widget. For example, on a '''[repeating_button]''' it will fire multiple times if the user holds the mouse button down.
 +
 
 +
=== on_double_click ===
 +
{{DevFeature1.19|14}}
 +
 
 +
* ''widget''.'''on_double_click''' &larr; '''function'''()
 +
* Available on: '''[toggle_panel]'''
 +
 
 +
Triggers when the user double clicks on the widget. Non-toggle panel widgets can be wrapped in a toggle panel to make use of this event handler.
 +
 
 +
=== on_left_click ===
 +
 
 +
* ''widget''.'''on_left_click''' &larr; '''function'''()
 +
* Available on: All widgets
 +
 
 +
Triggers when the user clicks on the widget.
 +
 
 +
=== on_link_click ===
 +
{{DevFeature1.19|9}}
 +
 
 +
* ''widget''.'''on_link_click''' &larr; '''function'''(''dest'')
 +
* Available on: '''[rich_label]'''
 +
 
 +
Triggers when the user clicks on a '''<ref>''' link inside a '''[rich_label]'''. The first argument '''dest''' is the target of the link.
 +
 
 +
=== on_modified ===
 +
 
 +
* ''widget''.'''on_modified''' &larr; '''function'''()
 +
* Available on: Most widgets, in particular '''[slider]''', '''[toggle_button]''', '''[listbox]''', '''[menu_button]''', '''[text_box]'''
 +
 
 +
Triggers when the user changes the value of the widget.
 +
 
 +
== Widget Length ==
 +
 
 +
{{DevFeature1.19|4}}
 +
 
 +
* '''#'''''widget''
 +
* Available on: '''[listbox]''', '''[multi_page]''', '''[tree_view]''', '''[tree_view_node]''', {{DevFeature1.19|6}} '''[stacked_widget]'''
 +
 
 +
Returns the total number of children in the specified container widget – for example, the number of rows in a list box, or the number of pages in a multi-page.
  
==== focus ====
+
== Widget Methods ==
* '''w.focus()'''
 
Switches the keyboard focus to the widget. This is often useful for dialogs containing a central listbox, so that it can be controlled with the keyboard as soon as it is displayed.
 
==== set_canvas ====
 
* '''w.set_canvas(layer index, content)'''
 
Sets the WML passed as the second argument as the canvas content (index given by the first argument) of the widget. The content of the WML table is described at [[GUICanvasWML]].
 
  
-- draw two rectangles in the upper-left corner of the window (empty path = window widget)
+
Any function defined in the [[LuaAPI/gui/widget|gui.widget]] module and taking a widget as its first parameter can be called as a method of a widget. This includes any functions that are added to the module by user code. Note that these methods are available even if the widget itself doesn't support that function, so in some cases it may be necessary to check '''widget.type''' before calling the method.
wesnoth.set_dialog_canvas(2, {
 
    T.rectangle { x = 20, y = 20, w = 20, h = 20, fill_color= "0,0,255,255" },
 
    T.rectangle { x = 30, y = 30, w = 20, h = 20, fill_color = "255,0,0,255" }
 
})
 
  
The meaning of the canvas index depends on the chosen widget. It may be the disabled / enabled states of the widget, or its background / foreground planes, or... For instance, overwriting canvas 1 of the window with an empty canvas causes the window to become transparent.
+
[[Category:Lua Reference]]
==== add_item ====
 
* '''w.add_item()'''
 
add an item to a widget, for example a listbox, returns the created item as a widget userdata.
 
==== add_item_of_type ====
 
* '''w.add_item_of_type("category")'''
 
add an item to a widget which Is a  heterogeneous container of different types of widgets, in particular multi_pages and treeviews
 

Latest revision as of 02:19, 11 March 2026

The widget userdata offers access to a widget of a GUI2 dialog. While there is only one type of widget userdata that covers all widgets including the window itself, the properties of a widget userdata are different for each type of widget. Indexing a widget's userdata can either be used to access a child widget or to set or get a property of a widget. Some properties are read-only or write-only; the properties depend on the type of the widget.

An example of accessing a child widget:

function preshow(dialog)
  local okay_button = dialog.okay_button
  -- okay_button is now a handle to the the widget's child with the id 'okay_button' 
end

(Version 1.19.x and later only) Some fields are only available in newer versions of Wesnoth. However, even in this case it might be possible to set the attribute in question before the dialog is first shown by adjusting its definition WML accordingly. See GUIWidgetInstanceWML for more information on WML attributes available for each widget class.

Widget Attributes

best_slider_length

(Version 1.19.6 and later only)

  • widget.best_slider_lengthlength
  • Available on: [slider]

Best length of the slider.

characters_per_line

(Version 1.19.6 and later only)

  • widget.labelint
  • Available on: [label]

Maximum characters this label should show per line.

editable

(Version 1.19.6 and later only)

  • widget.enabledboolean
  • Available on: [text_box]

If this text box is editable, i.e., read-only. (Text can be selected/copied but not modified.)

ellipsize_mode

(Version 1.19.6 and later only)

  • widget.ellipsize_modeellipsization mode string
  • Available on: Most widgets

Sets the Pango ellipsization mode for the widget. Accepts only one of the special strings:

String value
none
start
end
middle

enabled

  • widget.enabledboolean
  • Available on: Most widgets

help

(Version 1.19.6 and later only)

  • widget.enabledtext
  • Available on: Most widgets

Help text for this widget.

hint_image

(Version 1.19.6 and later only)

  • widget.hint_imagetext
  • Available on: [text_box], [combobox]

A image that is shown on the widget when it is not focused and has no other text.

hint_text

(Version 1.19.6 and later only)

  • widget.hint_texttext
  • Available on: [text_box], [combobox]

A background text that is shown on the widget when it is not focused and has no other text.

history

(Version 1.19.6 and later only)

  • widget.historytext
  • Available on: [text_box]

Input history of this text box.

indentation_step_size

(Version 1.19.6 and later only)

  • widget.indentation_step_sizeint
  • Available on: [tree_view]

How much should child nodes be offset from their parent node.

item_count

(Version 1.19.6 and later only)

  • widget.item_countnumber of items
  • Available on: [multi_page], [listbox], [combobox], [stacked_widget], [tree_view], [tree_view_node], [styled_widget]

The number of items in the container widget.

label

  • widget.labeltext
  • Available on: Most widgets, in particular [label], [button], [image]

The widget's label. Technically this is a special string used in the widget's wml definition. It usually does what one would expect, but also sets the image for image widgets. For [text_box], use text for initial values.

link_aware

(Version 1.19.6 and later only)

  • widget.link_awareboolean
  • Available on: [label], [rich_label], [scroll_label], [scroll_text]

Whether this widget recognizes inline links and allows clicking on them.

link_color

(Version 1.19.6 and later only)

  • widget.link_colorcolor string
  • Available on: [label], [rich_label]

Color of the inline link, as an hex string.

marked_up_text

  • widget.marked_up_texttext
  • Available on: Most widgets, in particular [label], [button]

Shortcut for setting label and use_markup=yes.

maximum_value_label

(Version 1.19.6 and later only)

  • widget.maximum_value_labeltext
  • Available on: [slider]

The text the slider's label shows when it is at maximum value position.

max_input_length

(Version 1.19.6 and later only)

  • widget.max_input_lengthtext
  • Available on: [text_box], [combobox]

Maximum number of character than can be input into this widget.

minimum_value_label

(Version 1.19.6 and later only)

  • widget.minimum_value_labeltext
  • Available on: [slider]

The text the slider's label shows when it is at minimum value position.

overflow_to_tooltip

(Version 1.19.6 and later only)

  • widget.overflow_to_tooltipboolean
  • Available on: Most widgets

path

  • widget.patharray of indices
  • Available on: [tree_view_node]

A table describing this node in the overall treeview. See selected_item_path for the meaning of the table..

percentage

  • widget.percentageposition
  • Available on: [progress_bar]

The current position of the progress bar, between 0 and 100.

selected

  • widget.selectedboolean
  • Available on: [toggle_button], [toggle_panel]

Whether the item is selected or not. Note that this should only be used for widgets that have only 2 states. In particular, there exist 3-State toggle_buttons (for example in listbox headers). For those, selected_index must be used instead.

selected_index

  • widget.selected_indexindex
  • Available on: [listbox], [multi_page], [stacked_widget], [menu_button], [toggle_button], [toggle_panel]

The selected index of the item. For [toggle_button] and [toggle_panel], this is the same as selected only encoded as a number (1 for false or 2 for true) instead of a boolean. For a [listbox]with has_maximum=false and more than one item selected, reading selected_index will return the first selected index. For a [stacked_widget], only the layer specified by selected_index will be displayed and receive events (callbacks will only be triggered on the selected layer). A selected_index of 0 represents all layers being selected, with events only being received by the layer with the highest index. Note that term selected for the layer of a stacked_widget is not the same as the selected widget attribute.

selected_item_path

  • widget.selected_item_patharray of indices
  • Available on: [tree_view]

A table describing the currently selected node. If for example, in the following treeview, Item 9 is selected, the result will be {2,1,3}.

+Section1
 +Subsection11
  *Item1
  *Item2
  *Item3
 +Subsection12
  *Item4
  *Item5
  *Item6
+Section2
 +Subsection21
  *Item7
  *Item8
  *Item9
 +Subsection22
  *Item10
  *Item11
  *Item12

step_size

(Version 1.19.6 and later only)

  • widget.step_sizeint
  • Available on: [slider]

text

  • widget.texttext
  • Available on: [text_box]

The text of the textbox.

text_alignment

(Version 1.19.6 and later only)

  • widget.text_alignmenttext alignment string
  • Available on: Most widgets

Sets the Pango text alignment for the widget. Accepts only one of the special strings:

String value
left
right
center

tooltip

  • widget.tooltiptext
  • Available on: Most widgets

type

  • widget.typestring
  • Available on: All widgets

Returns a string specifying the type of the widget.

unfolded

  • widget.unfoldedboolean
  • Available on: [tree_view_node], [tree_view]

Control whether a tree node is currently expanded or not.

unit

  • widget.unitunit or unit type
  • Available on: [unit_preview_pane]

Change the displayed unit or unit type in the preview pane.

use_markup

  • widget.use_markupboolean
  • Available on: Most widgets, in particular [label], [button]

Sets whether the widget's label will parse Pango formatting.

value

  • widget.valueposition
  • Available on: [slider]

The current position of the slider.

visible

  • widget.visiblevisibility string
  • Available on: Most widgets

Determines whether the widget is visible onscreen. The following visibility statuses are recognized:

String value Boolean shorthand Meaning
visible true The widget is visible and handles events.
hidden The widget is not visible, doesn't handle events, but still takes up space on the dialog grid.
invisible false The widget is not visible, doesn't handle events, and does not take up space on the dialog grid.

wrap

(Version 1.19.6 and later only)

  • widget.wrapboolean
  • Available on: [label]

Whether the text content in this label can wrap.

Widget Callbacks

on_button_click

  • widget.on_button_clickfunction()
  • Available on: [button], [repeating_button]

Triggers when the user clicks on the button. This can differ from on_left_click, depending on the type of widget. For example, on a [repeating_button] it will fire multiple times if the user holds the mouse button down.

on_double_click

(Version 1.19.14 and later only)

  • widget.on_double_clickfunction()
  • Available on: [toggle_panel]

Triggers when the user double clicks on the widget. Non-toggle panel widgets can be wrapped in a toggle panel to make use of this event handler.

on_left_click

  • widget.on_left_clickfunction()
  • Available on: All widgets

Triggers when the user clicks on the widget.

on_link_click

(Version 1.19.9 and later only)

  • widget.on_link_clickfunction(dest)
  • Available on: [rich_label]

Triggers when the user clicks on a <ref> link inside a [rich_label]. The first argument dest is the target of the link.

on_modified

  • widget.on_modifiedfunction()
  • Available on: Most widgets, in particular [slider], [toggle_button], [listbox], [menu_button], [text_box]

Triggers when the user changes the value of the widget.

Widget Length

(Version 1.19.4 and later only)

Returns the total number of children in the specified container widget – for example, the number of rows in a list box, or the number of pages in a multi-page.

Widget Methods

Any function defined in the gui.widget module and taking a widget as its first parameter can be called as a method of a widget. This includes any functions that are added to the module by user code. Note that these methods are available even if the widget itself doesn't support that function, so in some cases it may be necessary to check widget.type before calling the method.

This page was last edited on 11 March 2026, at 02:19.