✨ Announcing our seed funding led by Lux Capital! Read more about it on our blog
DocsBlogChangelog

Search documentation...

/

Star

12k+

[ Learn ]

[ Concepts ]

[ Reference ]

Switch


The Switch component is used as an alternative for the Checkbox component. You can switch between enabled or disabled states.

Switch off!

class SwitchState(rx.State):
    checked: bool = False
    is_checked: bool = "Switch off!"

    def change_check(self, checked: bool):
        self.checked = checked
        if self.checked:
            self.is_checked = "Switch on!"
        else:
            self.is_checked = "Switch off!"


def index():
    return rx.vstack(
        rx.heading(SwitchState.is_checked),
        rx.switch(
            is_checked=SwitchState.checked,
            on_change=SwitchState.change_check,
        ),
    )
You can also change the color scheme of the Switch component by passing the color_scheme argument. The default color scheme is blue.
rx.hstack(
    rx.switch(color_scheme="red"),
    rx.switch(color_scheme="green"),
    rx.switch(color_scheme="yellow"),
    rx.switch(color_scheme="blue"),
    rx.switch(color_scheme="purple"),
)

Switch


Toggleable switch component.


← SliderTextArea →

Copyright © 2023 Pynecone, Inc.