Toggle

A toggle represents a physical switch that allows someone to choose between two mutually exclusive options. For example, "On/Off", "Show/Hide". Choosing an option should produce an immediate result.

Properties#

NameTypeDefaultDescription
valueboolfalseCurrent value of the toggle.
labelstringA label for the toggle.
inlineboolfalseWhether the label (not the onText/offText) should be positioned inline with the toggle control.
onTextstringText to display when toggle is ON. Caution: when not providing on/off text user may get confused in differentiating the on/off states of the toggle.
offTextstringText to display when toggle is OFF. Caution: when not providing on/off text user may get confused in differentiating the on/off states of the toggle.
datastringAdditional data attached to the control. The value is passed in change event data along with a toggle state.

Events#

NameDescription
changeFires when the state of toggle is changed.

Examples#

Adding a new toggle:

enabled = page.add(Toggle(label="Dark mode", on_text="On", off_text="Off"))