mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
more docs
This commit is contained in:
22
docs/examples/introduction/clock.py
Normal file
22
docs/examples/introduction/clock.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from datetime import datetime
|
||||
|
||||
from textual.app import App
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
class Clock(Widget):
|
||||
def on_mount(self):
|
||||
self.styles.content_align = ("center", "middle")
|
||||
self.set_interval(1, self.refresh)
|
||||
|
||||
def render(self):
|
||||
return datetime.now().strftime("%c")
|
||||
|
||||
|
||||
class ClockApp(App):
|
||||
def compose(self):
|
||||
yield Clock()
|
||||
|
||||
|
||||
app = ClockApp()
|
||||
app.run()
|
||||
22
docs/examples/introduction/clock01.py
Normal file
22
docs/examples/introduction/clock01.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from datetime import datetime
|
||||
|
||||
from textual.app import App
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
class Clock(Widget):
|
||||
def on_mount(self):
|
||||
self.styles.content_align = ("center", "middle")
|
||||
self.set_interval(1, self.refresh)
|
||||
|
||||
def render(self):
|
||||
return datetime.now().strftime("%c")
|
||||
|
||||
|
||||
class ClockApp(App):
|
||||
def on_mount(self):
|
||||
self.mount(Clock())
|
||||
|
||||
|
||||
app = ClockApp()
|
||||
app.run()
|
||||
9
docs/examples/introduction/intro01.py
Normal file
9
docs/examples/introduction/intro01.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class ExampleApp(App):
|
||||
pass
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
app.run()
|
||||
29
docs/examples/introduction/intro02.py
Normal file
29
docs/examples/introduction/intro02.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class ExampleApp(App):
|
||||
|
||||
COLORS = [
|
||||
"white",
|
||||
"maroon",
|
||||
"red",
|
||||
"purple",
|
||||
"fuchsia",
|
||||
"olive",
|
||||
"yellow",
|
||||
"navy",
|
||||
"teal",
|
||||
"aqua",
|
||||
]
|
||||
|
||||
def on_mount(self):
|
||||
self.styles.background = "darkblue"
|
||||
|
||||
def on_key(self, event):
|
||||
if event.key.isdigit():
|
||||
self.styles.background = self.COLORS[int(event.key)]
|
||||
self.bell()
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
app.run()
|
||||
17
docs/examples/styles/width.py
Normal file
17
docs/examples/styles/width.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from textual.app import App
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
class WidthApp(App):
|
||||
CSS = """
|
||||
Widget {
|
||||
background: blue;
|
||||
width: 50%;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self):
|
||||
yield Widget()
|
||||
|
||||
|
||||
app = WidthApp()
|
||||
Reference in New Issue
Block a user