Skip to content

cannot reffer to dict value when I use use "is_on=self.bind()" on Switch feature #179

Answered by Aran-Fey
Nachsh asked this question in Q&A
Discussion options

You must be logged in to vote

Attribute bindings cannot be combined with any extra code. In other words, is_on=self.bind().led_status is valid, but is_on=self.bind().led_status['red'] is not. You will need to update your dict in your on_change event handler, like so:

class Example(rio.Component):
    led_status: dict = {
        "red": False,
        "green": False,
        "blue": False,
        "ir": False,
    }

    def on_led_change(self, event: rio.SwitchChangeEvent):
        self.led_status['red'] = event.is_on

    def build(self):
        return rio.Switch(
            is_on=self.led_status["red"],
            on_change=self.on_led_change,
        )

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Nachsh
Comment options

Answer selected by Nachsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants