-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoose_which_screen.py
40 lines (28 loc) · 1.07 KB
/
choose_which_screen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from textual import on
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.screen import Screen
from textual.widgets import Button, Label
class ChoiceScreen(Screen):
def compose(self) -> ComposeResult:
with Horizontal():
yield Button("Screen A", id="choose-A")
yield Button("Screen B", id="choose-B")
@on(Button.Pressed)
def return_choice(self, event: Button.Pressed) -> None:
self.dismiss(event.button.id)
class ScreenA(Screen):
def compose(self) -> ComposeResult:
yield Label("Thank you for choosing option A")
class ScreenB(Screen):
def compose(self) -> ComposeResult:
yield Label("Thank you for choosing option B")
class ChoiceApp(App[None]):
def on_mount(self) -> None:
def process_choice(choice_id: str) -> None:
if choice_id == "choose-A":
self.push_screen(ScreenA())
else:
self.push_screen(ScreenB())
self.push_screen(ChoiceScreen(), callback=process_choice)
ChoiceApp().run()