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()
|
||||
Reference in New Issue
Block a user