mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
return types and buttons
This commit is contained in:
18
docs/examples/app/question01.py
Normal file
18
docs/examples/app/question01.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static, Button
|
||||
|
||||
|
||||
class QuestionApp(App[str]):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Do you love Textual?")
|
||||
yield Button("Yes", id="yes", variant="primary")
|
||||
yield Button("No", id="no", variant="error")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.exit(event.button.id)
|
||||
|
||||
|
||||
app = QuestionApp()
|
||||
if __name__ == "__main__":
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
20
docs/examples/app/question02.py
Normal file
20
docs/examples/app/question02.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static, Button
|
||||
|
||||
|
||||
class QuestionApp(App[str]):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Do you love Textual?")
|
||||
yield (yes := Button("Yes", id="yes"))
|
||||
yes.variant = "primary"
|
||||
yield (no := Button("No", id="no"))
|
||||
no.variant = "error"
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.exit(event.button.id)
|
||||
|
||||
|
||||
app = QuestionApp()
|
||||
if __name__ == "__main__":
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
Reference in New Issue
Block a user