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- TBDbutton- 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- Whether this semantics node should introduce its own semantic container.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- Whether the semantics information fromcontentshould be excluded.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 thecontentcontrol.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 thecontent.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 thevalueis coming from a field that supports multiline text editing.obscured- Whethervalueshould 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 thevalueof thecontentcontrol.
Events
on_copy- Called when the current selection is copied to the clipboard.on_cut- Called when the current selection is cut to the clipboard.on_decrease- Called when the value represented by the semantics node is decreased.on_did_gain_accessibility_focus- Called when the node has gained accessibility focus.on_did_lose_accessibility_focus- Called when the node has lost accessibility focus.on_dismiss- Called when the node is dismissed.on_double_tap- Reserved for a semantic double-tap action.on_increase- Called when the value represented by the semantics node is increased.on_long_press- 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_text- A hint describing what happens when the user activateson_long_press.on_move_cursor_backward_by_character- Called when the cursor is moved backward by one character.on_move_cursor_forward_by_character- Called when the cursor is moved forward by one character.on_paste- Called when the current content of the clipboard is pasted.on_scroll_down- Called when a user moves their finger across the screen from top to bottom.on_scroll_left- Called when a user moves their finger across the screen from right to left.on_scroll_right- Called when a user moves their finger across the screen from left to right.on_scroll_up- Called when a user moves their finger across the screen from bottom to top.on_set_text- Called when a user wants to replace the current text in the text field with a new text.on_tap- Called when this control is tapped.on_tap_hint_text- A hint describing what happens when the user activateson_tap.
Examples
Semantics
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
buttonclass-attributeinstance-attribute
button: bool | None = NoneWhether this subtree represents a button.
checkedclass-attributeinstance-attribute
checked: bool | None = NoneWhether this subtree represents a checkbox or similar widget with a "checked" state, and what its current state is.
containerclass-attributeinstance-attribute
container: bool | None = NoneWhether this semantics node should introduce its own semantic container.
A container groups the semantics of its subtree into a distinct node instead of always merging with surrounding semantics.
current_value_lengthclass-attributeinstance-attribute
current_value_length: int | None = NoneThe current number of characters that have been entered into an editable text field.
decreased_valueclass-attributeinstance-attribute
decreased_value: str | None = NoneThe value that the semantics node represents when it is decreased.
exclude_semanticsclass-attributeinstance-attribute
exclude_semantics: bool = FalseWhether the semantics information from content should be excluded.
When True, only the semantics configured on this Semantics
wrapper are exposed.
expandedclass-attributeinstance-attribute
expanded: bool | None = NoneWhether this subtree represents something that can be in an "expanded" or "collapsed" state.
focusclass-attributeinstance-attribute
focus: bool | None = NoneWhether the node currently holds input focus.
focusableclass-attributeinstance-attribute
focusable: bool | None = NoneWhether the node is able to hold input focus.
headerclass-attributeinstance-attribute
header: bool | None = NoneWhether this subtree represents a header.
heading_levelclass-attributeinstance-attribute
heading_level: int | None = NoneThe heading level in the DOM document structure.
hiddenclass-attributeinstance-attribute
hidden: bool | None = NoneWhether this subtree is currently hidden.
hint_textclass-attributeinstance-attribute
hint_text: str | None = NoneA brief textual description of the result of an action performed on the content control.
imageclass-attributeinstance-attribute
image: bool | None = NoneWhether the node represents an image.
increased_valueclass-attributeinstance-attribute
increased_value: str | None = NoneThe value that the semantics node represents when it is increased.
labelclass-attributeinstance-attribute
label: str | None = NoneA textual description of the content.
linkclass-attributeinstance-attribute
link: bool | None = NoneWhether this subtree represents a link.