Skip to main content

Semantics

Provides semantic annotations for the control tree, describing the meaning and purpose of controls.

These annotations are utilized by accessibility tools, search engines, and semantic analysis software to better understand the structure and functionality of the application.

Inherits: Control

Properties

  • badge - TBD
  • button - Whether this subtree represents a button.
  • checked - Whether this subtree represents a checkbox or similar widget with a "checked" state, and what its current state is.
  • container - TBD
  • content - The Control to annotate.
  • current_value_length - The current number of characters that have been entered into an editable text field.
  • decreased_value - The value that the semantics node represents when it is decreased.
  • exclude_semantics - TBD
  • expanded - Whether this subtree represents something that can be in an "expanded" or "collapsed" state.
  • focus - Whether the node currently holds input focus.
  • focusable - Whether the node is able to hold input focus.
  • header - Whether this subtree represents a header.
  • heading_level - The heading level in the DOM document structure.
  • hidden - Whether this subtree is currently hidden.
  • hint_text - A brief textual description of the result of an action performed on the content control.
  • image - Whether the node represents an image.
  • increased_value - The value that the semantics node represents when it is increased.
  • label - A textual description of the content.
  • link - Whether this subtree represents a link.
  • live_region - Whether this subtree should be considered a live region.
  • max_value_length - The maximum number of characters that can be entered into an editable text field.
  • mixed - Whether this subtree represents a checkbox or similar control with a "half-checked" state or similar, and whether it is currently in this half-checked state.
  • multiline - Whether the value is coming from a field that supports multiline text editing.
  • obscured - Whether value should be obscured.
  • read_only - Whether this subtree is read only.
  • selected - Whether this subtree represents something that can be in a selected or unselected state, and what its current state is.
  • slider - Whether this subtree represents a slider.
  • textfield - Whether this subtree represents a text field.
  • toggled - Whether this subtree represents a toggle switch or similar widget with an "on" state, and what its current state is.
  • tooltip - A textual description of the widget's tooltip.
  • value - A textual description of the value of the content control.

Events

Examples

Basic Example

import flet as ft


def main(page: ft.Page):
def handle_gain_accessibility_focus(e: ft.Event[ft.Semantics]):
print("focus gained")

def handle_lose_accessibility_focus(e: ft.Event[ft.Semantics]):
print("focus lost")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Semantics(
label="Input your occupation",
on_did_gain_accessibility_focus=handle_gain_accessibility_focus,
on_did_lose_accessibility_focus=handle_lose_accessibility_focus,
content=ft.TextField(
label="Occupation",
hint_text="Use 20 words or less",
value="What is your occupation?",
),
),
ft.Icon(ft.Icons.SETTINGS, color="#c1c1c1"),
]
),
)
)


if __name__ == "__main__":
ft.run(main)

Properties

badgeclass-attributeinstance-attribute

badge: Optional[BadgeValue] = None

TBD

buttonclass-attributeinstance-attribute

button: Optional[bool] = None

Whether this subtree represents a button.

checkedclass-attributeinstance-attribute

checked: Optional[bool] = None

Whether this subtree represents a checkbox or similar widget with a "checked" state, and what its current state is.

containerclass-attributeinstance-attribute

container: Optional[bool] = None

TBD

contentclass-attributeinstance-attribute

content: Optional[Control] = None

The Control to annotate.

current_value_lengthclass-attributeinstance-attribute

current_value_length: Optional[int] = None

The current number of characters that have been entered into an editable text field.

decreased_valueclass-attributeinstance-attribute

decreased_value: Optional[str] = None

The value that the semantics node represents when it is decreased.

exclude_semanticsclass-attributeinstance-attribute

exclude_semantics: bool = False

TBD

expandedclass-attributeinstance-attribute

expanded: Optional[bool] = None

Whether this subtree represents something that can be in an "expanded" or "collapsed" state.

focusclass-attributeinstance-attribute

focus: Optional[bool] = None

Whether the node currently holds input focus.

focusableclass-attributeinstance-attribute

focusable: Optional[bool] = None

Whether the node is able to hold input focus.

headerclass-attributeinstance-attribute

header: Optional[bool] = None

Whether this subtree represents a header.

heading_levelclass-attributeinstance-attribute

heading_level: Optional[int] = None

The heading level in the DOM document structure.

hiddenclass-attributeinstance-attribute

hidden: Optional[bool] = None

Whether this subtree is currently hidden.

hint_textclass-attributeinstance-attribute

hint_text: Optional[str] = None

A brief textual description of the result of an action performed on the content control.

imageclass-attributeinstance-attribute

image: Optional[bool] = None

Whether the node represents an image.

increased_valueclass-attributeinstance-attribute

increased_value: Optional[str] = None

The value that the semantics node represents when it is increased.

labelclass-attributeinstance-attribute

label: Optional[str] = None

A textual description of the content.

link: Optional[bool] = None

Whether this subtree represents a link.

live_regionclass-attributeinstance-attribute

live_region: Optional[bool] = None

Whether this subtree should be considered a live region.

max_value_lengthclass-attributeinstance-attribute

max_value_length: Optional[Number] = None

The maximum number of characters that can be entered into an editable text field.

mixedclass-attributeinstance-attribute

mixed: Optional[bool] = None

Whether this subtree represents a checkbox or similar control with a "half-checked" state or similar, and whether it is currently in this half-checked state.

multilineclass-attributeinstance-attribute

multiline: Optional[bool] = None

Whether the value is coming from a field that supports multiline text editing.

obscuredclass-attributeinstance-attribute

obscured: Optional[bool] = None

Whether value should be obscured.

read_onlyclass-attributeinstance-attribute

read_only: Optional[bool] = None

Whether this subtree is read only.

selectedclass-attributeinstance-attribute

selected: Optional[bool] = None

Whether this subtree represents something that can be in a selected or unselected state, and what its current state is.

sliderclass-attributeinstance-attribute

slider: Optional[bool] = None

Whether this subtree represents a slider.

textfieldclass-attributeinstance-attribute

textfield: Optional[bool] = None

Whether this subtree represents a text field.

toggledclass-attributeinstance-attribute

toggled: Optional[bool] = None

Whether this subtree represents a toggle switch or similar widget with an "on" state, and what its current state is.

tooltipclass-attributeinstance-attribute

tooltip: Optional[str] = None

A textual description of the widget's tooltip.

valueclass-attributeinstance-attribute

value: Optional[str] = None

A textual description of the value of the content control.

Events

on_copyclass-attributeinstance-attribute

on_copy: Optional[ControlEventHandler[Semantics]] = None

Called when the current selection is copied to the clipboard.

on_cutclass-attributeinstance-attribute

on_cut: Optional[ControlEventHandler[Semantics]] = None

Called when the current selection is cut to the clipboard.

on_decreaseclass-attributeinstance-attribute

on_decrease: Optional[ControlEventHandler[Semantics]] = None

Called when the value represented by the semantics node is decreased.

on_did_gain_accessibility_focusclass-attributeinstance-attribute

on_did_gain_accessibility_focus: Optional[ControlEventHandler[Semantics]] = None

Called when the node has gained accessibility focus.

on_did_lose_accessibility_focusclass-attributeinstance-attribute

on_did_lose_accessibility_focus: Optional[ControlEventHandler[Semantics]] = None

Called when the node has lost accessibility focus.

on_dismissclass-attributeinstance-attribute

on_dismiss: Optional[ControlEventHandler[Semantics]] = None

Called when the node is dismissed.

on_double_tapclass-attributeinstance-attribute

on_double_tap: Optional[ControlEventHandler[Semantics]] = None

TBD

on_increaseclass-attributeinstance-attribute

on_increase: Optional[ControlEventHandler[Semantics]] = None

Called when the value represented by the semantics node is increased.

on_long_pressclass-attributeinstance-attribute

on_long_press: Optional[ControlEventHandler[Semantics]] = None

Called when the node is long-pressed (pressing and holding the screen with the finger for a few seconds without moving it).

on_long_press_hint_textclass-attributeinstance-attribute

on_long_press_hint_text: Optional[str] = None

TBD

on_move_cursor_backward_by_characterclass-attributeinstance-attribute

on_move_cursor_backward_by_character: Optional[ControlEventHandler[Semantics]] = None

Called when the cursor is moved backward by one character.

on_move_cursor_forward_by_characterclass-attributeinstance-attribute

on_move_cursor_forward_by_character: Optional[ControlEventHandler[Semantics]] = None

Called when the cursor is moved forward by one character.

on_pasteclass-attributeinstance-attribute

on_paste: Optional[ControlEventHandler[Semantics]] = None

Called when the current content of the clipboard is pasted.

on_scroll_downclass-attributeinstance-attribute

on_scroll_down: Optional[ControlEventHandler[Semantics]] = None

Called when a user moves their finger across the screen from top to bottom.

on_scroll_leftclass-attributeinstance-attribute

on_scroll_left: Optional[ControlEventHandler[Semantics]] = None

Called when a user moves their finger across the screen from right to left.

on_scroll_rightclass-attributeinstance-attribute

on_scroll_right: Optional[ControlEventHandler[Semantics]] = None

Called when a user moves their finger across the screen from left to right.

on_scroll_upclass-attributeinstance-attribute

on_scroll_up: Optional[ControlEventHandler[Semantics]] = None

Called when a user moves their finger across the screen from bottom to top.

on_set_textclass-attributeinstance-attribute

on_set_text: Optional[ControlEventHandler[Semantics]] = None

Called when a user wants to replace the current text in the text field with a new text.

Voice access users can trigger this handler by speaking type <text> to their Android devices.

on_tapclass-attributeinstance-attribute

on_tap: Optional[ControlEventHandler[Semantics]] = None

Called when this control is tapped.

on_tap_hint_textclass-attributeinstance-attribute

on_tap_hint_text: Optional[str] = None

TBD