Skip to content

Color of Static not changing when updated #6289

@dirkterrell

Description

@dirkterrell

Using textual 6.8.0 and python 3.14 (GIL and no GIL), I am finding unexpected behavior when trying to set the color of a Static widget in code. I have a Checkbox and when a check/uncheck event occurs, I use styles.color to change the color but nothing changes in the terminal. If the terminal window loses focus and then I bring it back and hover the mouse over the text label, the correct color appears. Here is a simple test app that shows the behavior.

from textual.app import App, ComposeResult
from textual.widgets import Checkbox, Static

class CheckboxApp(App):
    def compose(self) -> ComposeResult:
        yield Checkbox("Change text color", id="my_checkbox")
        yield Static("I am static text.", id="my_text")

    def on_checkbox_changed(self, event: Checkbox.Changed) -> None:
        """An event handler called when a checkbox is changed."""
        text_widget = self.query_one("#my_text", Static)
        if event.value:
            text_widget.styles.color = "green"
        else:
            text_widget.styles.color = "red"
        self.refresh()

if __name__ == "__main__":#	print(os.get_terminal_size())
	app = CheckboxApp()
	app.run()

I have tried using reactives, calling refresh(), different shells (default terminal on Almalinux 9, xterm, Kitty) but the results are always the same: checking/unchecking the box leads to no change in the appearance of the app but losing window focus, getting it back and then hovering over the Static does cause the color to change. The problem sounds a bit like issue #6280.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions