Skip to content

toggle class

A series of toggle buttons that the user can select.

Methods

__init__()

__init__(
    value=None,
    theme=False,
    allow_unselect=False,
    unselected_value=None,
    mode=None,
    label=None,
    width=None,
    lov=None,
    adapter=None, # lambda x: str(x)
    type=None, # Type name of the first lov element
    value_by_id=False,
    on_change=None,
    propagate=None, # App config
    active=True,
    id=None,
    properties=None,
    class_name=None,
    hover_text=None,
) -> None

Create a new toggle element.

Parameters:

Name Type Description Default

value

Any
dynamic

Bound to the selection value.

None

theme

bool

If set, this toggle control acts as a way to set the application Theme (dark or light).

False

allow_unselect

bool

If set, this allows de-selection and the value is set to unselected_value.

False

unselected_value

Any

Value assigned to value when no item is selected.

None

mode

str

Define the way the toggle is displayed:

  • "theme": synonym for setting the theme property to True
None

label

str

The label associated with the toggle.

None

width

Union[str, int]

The width of the element.

None

lov

dict[str, Any]

The list of values. See the section on List of Values for more details.

None

adapter

Union[str, Callable]

A function or the name of the function that transforms an element of lov into a tuple(id:str, label:Union[str,Icon]).
The default value is a function that returns the string representation of the lov element.

lambda x: str(x)

type

str

This property is required if lov contains a non-specific type of data (e.g., a dictionary).
Then:

  • value must be of that type
  • lov must be an iterable containing elements of this type
  • The function set to adapter will receive an object of this type.

The default value is the type of the first element in lov.

Type name of the first lov element

value_by_id

bool

If False, the selection value (in value) is the selected element in lov. If set to True, then value is set to the id of the selected element in lov.

False

on_change

Union[str, Callable]

A function or the name of a function that is triggered when the value is updated.
This function is invoked with the following parameters:

  • state (State): the state instance.
  • var_name (str): the variable name.
  • value (Any): the new value.
None

propagate

bool

Allows the control's main value to be automatically propagated.
The default value is defined at the application configuration level by the propagate configuration option.
If True, any change to the control's value is immediately reflected in the bound application variable.

App config

active

bool
dynamic

Indicates if this component is active.
An inactive component allows no user interaction.

True

id

str

The identifier that is assigned to the rendered HTML component.

None

properties

dict[str, Any]

Bound to a dictionary that contains additional properties for this element.

None

class_name

str
dynamic

The list of CSS class names that are associated with the generated HTML Element.
These class names are added to the default taipy-toggle class name.

None

hover_text

str
dynamic

The information that is displayed when the user hovers over this element.

None