Added compose event, more color docs

This commit is contained in:
Will McGugan
2022-09-12 12:47:14 +01:00
parent 32079fc8f7
commit 4a459dbd20
12 changed files with 165 additions and 28 deletions

View File

@@ -0,0 +1,17 @@
from textual.app import App, ComposeResult
from textual.widgets import Static
class WidgetApp(App):
def compose(self) -> ComposeResult:
self.widget = Static("Textual")
yield self.widget
def on_mount(self) -> None:
self.widget.styles.background = "darkblue"
self.widget.styles.border = ("heavy", "white")
app = WidgetApp()
if __name__ == "__main__":
app.run()

View File

@@ -0,0 +1,24 @@
from textual.app import App, ComposeResult
from textual.color import Color
from textual.widgets import Static
class ColorApp(App):
def compose(self) -> ComposeResult:
self.widget1 = Static("Textual One")
yield self.widget1
self.widget2 = Static("Textual Two")
yield self.widget2
self.widget3 = Static("Textual Three")
yield self.widget3
def on_mount(self) -> None:
self.widget1.styles.background = "#9932CC"
self.widget2.styles.background = "hsl(150,42.9%,49.4%)"
self.widget2.styles.color = "blue"
self.widget3.styles.background = Color(191, 78, 96)
app = ColorApp()
if __name__ == "__main__":
app.run()

View File

@@ -0,0 +1,18 @@
from textual.app import App, ComposeResult
from textual.color import Color
from textual.widgets import Static
class ColorApp(App):
def compose(self) -> ComposeResult:
self.widgets = [Static(f"Textual {n+1}") for n in range(10)]
yield from self.widgets
def on_mount(self) -> None:
for index, widget in enumerate(self.widgets, 1):
widget.styles.background = Color(191, 78, 96, index * 0.1)
app = ColorApp()
if __name__ == "__main__":
app.run()

View File

@@ -0,0 +1,17 @@
from textual.app import App, ComposeResult
from textual.widgets import Static
class WidgetApp(App):
def compose(self) -> ComposeResult:
self.widget = Static("Textual")
yield self.widget
def on_mount(self) -> None:
self.widget.styles.background = "darkblue"
self.widget.styles.border = ("heavy", "white")
app = WidgetApp()
if __name__ == "__main__":
app.run()