-
|
I want to disable/enable a button when some precondition is met (in this example, another button has been clicked). Why does this apparently not perform a re-layout when from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widgets import Button
class MyApp(App):
ready = reactive(False, layout=True)
async def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == 'enable':
self.ready = True
def compose(self) -> ComposeResult:
yield Button('Enable', variant='primary', id='enable')
yield Button('Do the thing', variant='primary', id='do_the_thing', disabled=not self.ready)
if __name__ == '__main__':
MyApp().run() |
Beta Was this translation helpful? Give feedback.
Answered by
davep
Nov 23, 2022
Replies: 1 comment 1 reply
-
|
A re-layout isn't the same as calling from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widgets import Button
class MyApp(App):
ready = reactive(False,init=False)
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == 'enable':
self.ready = True
def watch_ready(self, ready: bool) -> None:
self.query_one( "#do_the_thing", Button).disabled = not ready
def compose(self) -> ComposeResult:
yield Button('Enable', variant='primary', id='enable')
yield Button('Do the thing', variant='primary', id='do_the_thing', disabled=not self.ready)
if __name__ == '__main__':
MyApp().run() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nnmm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A re-layout isn't the same as calling
compose. Thecomposemethod builds your app content just the once so it's not going to be called again. To react toreadybeing changed you want to be using a watch method . So perhaps go with something more like this: