How to maintain the same theme across all of the Named Screens? #1992
Answered
by
davep
learnbyexample
asked this question in
Q&A
-
Here's a sample app with multiple screens: from textual.app import App
from textual.binding import Binding
from textual.widgets import Footer, Label
from textual.screen import Screen
class TextScreen(Screen):
BINDINGS = [('escape', 'pop_screen', 'Go back')]
def __init__(self, s):
super().__init__()
self.s = s
def compose(self):
yield Label(self.s)
yield Footer()
def on_show(self):
self.refresh()
class MainScreen(Screen):
BINDINGS = [Binding('ctrl+a', "push_screen('one')", 'Screen1'),
Binding('ctrl+s', "push_screen('two')", 'Screen2')]
def compose(self):
yield Label('Main Screen')
yield Footer()
class Test(App):
BINDINGS = [('ctrl+t', 'toggle_theme', 'Theme')]
SCREENS = {'main': MainScreen(),
'one': TextScreen('This is Screen 1'),
'two': TextScreen('This is Screen 2')}
CSS = 'Screen { align: center middle; }'
def on_mount(self):
self.dark = False
self.push_screen('main')
def action_toggle_theme(self):
self.dark ^= True
if __name__ == '__main__':
app = Test()
app.run() And here's a sample recording: screen_theme.mp4Actions taken in the above recording:
I couldn't figure out how to change theme for all the screens when theme is toggled. Closest I could think of is: def on_show(self):
self.refresh() which doesn't seem to work. (I'm not sure if |
Beta Was this translation helpful? Give feedback.
Answered by
davep
Mar 9, 2023
Replies: 1 comment 4 replies
-
Good catch! Looks like a bug to me so I'll create an issue for it. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
davep
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good catch! Looks like a bug to me so I'll create an issue for it.