Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

I've some trouble studing python flet. Is it bug or my fault?

$
0
0

Please help me find the reason for this code behaviorThere are 3 identical boxes (flet Container()) with switch (flet Switch()).Only switch in first box "unit_view1" is available for switching. Other two are not.Why ???I can't find any reason that interferes with the behavior of the switches

import flet as ftdef _name_row(unit_name):    return ft.Container(alignment=ft.alignment.center, content=ft.Text(value=unit_name, size=36))def set_on_off(value):    print("unit is", "on" if value else "off")class Unit(ft.UserControl):    def __init__(self, unit_name: str):        super().__init__()        self.unit_name = unit_name    def build(self):        _cnt = ft.Container(            padding=10,            width=250,            border=ft.border.all(3),            border_radius=30,            content=ft.Column(                controls=[                    ft.Switch(                        label="Вкл",                        active_color="green",                        on_change=set_on_off                    ),                    ft.Divider(),                    _name_row(self.unit_name),                    ft.Divider(),                ]            )        )        return _cntclass UnitsView(ft.UserControl):    def __init__(self):        super().__init__()        self.unit_view1 = Unit(unit_name="Unit 1")        self.unit_view2 = Unit(unit_name="Unit 2")        self.unit_view3 = Unit(unit_name="Unit 3")    def build(self):        _cnt = ft.Container(            alignment=ft.alignment.center,            padding=50,            width=400,            content=ft.Row(                spacing=10,                controls=[                    self.unit_view1,                    ft.VerticalDivider(),                    self.unit_view2,                    ft.VerticalDivider(),                    self.unit_view3,                ],            ),        )        return _cntdef main(page: ft.Page):    page.window_width = 960    page.window_height = 300    page.add(UnitsView())if __name__ == "__main__":    ft.app(target=main)

View of appI tested a similar one without classes, I only use simple Flet controls it and it works there.


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>