Using Classes and Updating Isolated Controls - Issue #1104
-
| QuestionIn a project that I'm working on it requires for me to use separate/isolated classes to represent each control. Here's an example where I have 3 separate classes; Control1, Control2, and Hamburger_btn. When I click the button inside of Hamburger_btn, only the Control2 class gets updated instead of both Control1 and Control2. What exactly am I doing wrong in this example below? Code sampleimport flet as ft
class Control1(ft.UserControl):
    def __init__(self):
        super().__init__()
        self.con1 = ft.Ref[ft.Container]
    def build(self):
        self.con1 = ft.Container(bgcolor='blue', width=200, height=200, border_radius=6, margin=10, ref=self.con1)
        return self.con1
class Control2(ft.UserControl):
    def __init__(self):
        super().__init__()
        self.con2 = ft.Ref[ft.Container]
    def build(self):
        self.con2 = ft.Container(bgcolor='yellow', width=200, height=200, border_radius=6, margin=10, ref=self.con2)
        return self.con2
class Hamburger_btn(Control1, Control2):
    def __init__(self):
        super().__init__()
    def build(self):
        self.hamburger_btn = ft.TextButton(text='Change Colors', style=ft.ButtonStyle(bgcolor='red', color='white'),
                                           on_click=self.change_color)
        return self.hamburger_btn
    def change_color(self, e):
        self.con1.current.bgcolor = 'red'
        self.con1.current.update()
        self.con2.current.bgcolor = 'orange'
        self.con2.current.update()
def main(page:ft.Page):
    page.window_width = 800
    page.window_height = 500
    page.window_center()
    page.bgcolor = '#333333'
    page.padding = 0
    page.theme_mode = 'light'
    page.update()
    page.add(ft.Row([Hamburger_btn(), Control1(), Control2()]))
ft.app(target=main)Error messageNo response ------------------------------------------------------
 | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
| @AaronCatolico did you try other ways like: 
 IMO, multiple inheritance and MRO is best avoided. | 
Beta Was this translation helpful? Give feedback.
@AaronCatolico did you try other ways like:
Control1andControl2inside thebuild()or__init__()ofHamburger_btn, as in,Hamburger_btnis aUserControlcomposed of otherUserControllikeControl1andControl2.Refwhen instantiatingHamburger_btn.IMO, multiple inheritance and MRO is best avoided.