-
Notifications
You must be signed in to change notification settings - Fork 613
Open
Description
Discussed in #6112
Originally posted by AquamarineCyan February 2, 2026
Question
When I updated button.bgcolor from None to other colors, I did not receive any changes, including in the ButtonStyle. But in the Container, everything is normal.
Code sample
import flet as ft
ft.context.disable_auto_update()
def main(page: ft.Page):
def change_button_bgcolor(): # do not work
if button.bgcolor is None:
button.bgcolor = ft.Colors.GREEN
else:
button.bgcolor = None
button.update()
def change_button_bgcolor_if_yellow(): # work
if button.bgcolor is ft.Colors.YELLOW:
button.bgcolor = ft.Colors.GREEN
else:
button.bgcolor = ft.Colors.YELLOW
button.update()
def change_button_style_bgcolor():
if button.style is None or button.style.bgcolor is None:
if button.style is None:
button.style = ft.ButtonStyle(bgcolor=ft.Colors.GREEN)
else:
button.style.bgcolor = None # do not work
else:
button.style.bgcolor = None
button.update()
def change_container_bgcolor():
if container.bgcolor is None:
container.bgcolor = ft.Colors.RED
else:
container.bgcolor = None
container.update()
button = ft.Button(
"Click me to change bgcolor",
# bgcolor=None,
on_click=change_button_bgcolor,
# on_click=change_button_style_bgcolor,
# ------
# bgcolor=ft.Colors.YELLOW,
# on_click=change_button_bgcolor_if_yellow, # it work
)
container = ft.Container(
ft.Text("Click me to change bgcolor"),
bgcolor=ft.Colors.YELLOW,
width=200,
height=50,
on_click=change_container_bgcolor,
)
page.add(button, container)
if __name__ == "__main__":
ft.run(main)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
👀 In review