mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
app basics and doc structure
This commit is contained in:
30
docs/examples/app/event01.py
Normal file
30
docs/examples/app/event01.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from textual.app import App
|
||||
from textual import events
|
||||
|
||||
|
||||
class EventApp(App):
|
||||
|
||||
COLORS = [
|
||||
"white",
|
||||
"maroon",
|
||||
"red",
|
||||
"purple",
|
||||
"fuchsia",
|
||||
"olive",
|
||||
"yellow",
|
||||
"navy",
|
||||
"teal",
|
||||
"aqua",
|
||||
]
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.styles.background = "darkblue"
|
||||
|
||||
def on_key(self, event: events.Key) -> None:
|
||||
if event.key.isdecimal():
|
||||
self.styles.background = self.COLORS[int(event.key)]
|
||||
|
||||
|
||||
app = EventApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
14
docs/examples/app/return.py
Normal file
14
docs/examples/app/return.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Button
|
||||
|
||||
|
||||
class ButtonsApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Button("Paul")
|
||||
yield Button("Duncan")
|
||||
yield Button("Chani")
|
||||
|
||||
|
||||
app = ButtonsApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
5
docs/examples/app/simple01.py
Normal file
5
docs/examples/app/simple01.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class MyApp(App):
|
||||
pass
|
||||
10
docs/examples/app/simple02.py
Normal file
10
docs/examples/app/simple02.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class MyApp(App):
|
||||
pass
|
||||
|
||||
|
||||
app = MyApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
15
docs/examples/app/widgets01.py
Normal file
15
docs/examples/app/widgets01.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Welcome
|
||||
|
||||
|
||||
class WelcomeApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Welcome()
|
||||
|
||||
def on_button_pressed(self) -> None:
|
||||
self.exit()
|
||||
|
||||
|
||||
app = WelcomeApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
Reference in New Issue
Block a user