Skip to content

bug: First Button.bgcolor update is ignored when initial value is None #6118

@ndonkoHenri

Description

@ndonkoHenri

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.

button_bgcolor_error

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions