mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Document setting app (sub)title.
This commit is contained in:
22
docs/examples/app/question_title01.py
Normal file
22
docs/examples/app/question_title01.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Button, Header, Label
|
||||
|
||||
|
||||
class MyApp(App[str]):
|
||||
TITLE = "A Question App"
|
||||
SUB_TITLE = "The most important question"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield Label("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)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = MyApp()
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
27
docs/examples/app/question_title02.py
Normal file
27
docs/examples/app/question_title02.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.events import Key
|
||||
from textual.widgets import Button, Header, Label
|
||||
|
||||
|
||||
class MyApp(App[str]):
|
||||
TITLE = "A Question App"
|
||||
SUB_TITLE = "The most important question"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield Label("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)
|
||||
|
||||
def on_key(self, event: Key):
|
||||
self.title = event.key
|
||||
self.sub_title = f"You just pressed {event.key}!"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = MyApp()
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
Reference in New Issue
Block a user