Skip to content

Component classes reactive to theme change? #5502

Answered by TomJGooding
TomJGooding asked this question in Q&A
Discussion options

You must be logged in to vote

Just an update for anyone else who might stumble on this: Textual v2.0 added Content objects, which could be a better solution for using CSS variables.

Here's my updated example:

from textual import on
from textual.app import App, ComposeResult
from textual.content import Content
from textual.reactive import var
from textual.widgets import OptionList, Static


class MyOptionList(OptionList):
    def on_mount(self) -> None:
        self.add_options([self._make_entry_content(i) for i in range(20)])
        self.highlighted = 0

    def _make_entry_content(self, index: int) -> Content:
        return Content.from_markup(
            "[$accent]Option $index[/] <- This color now changes!",
   …

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@willmcgugan
Comment options

@TomJGooding
Comment options

@willmcgugan
Comment options

@TomJGooding
Comment options

@TomJGooding
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by TomJGooding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants