mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
32 lines
726 B
Python
32 lines
726 B
Python
from textual.app import App, ComposeResult
|
|
from textual.color import Color
|
|
from textual.widgets import Footer, Static
|
|
|
|
|
|
class Bar(Static):
|
|
pass
|
|
|
|
|
|
class BindingApp(App):
|
|
|
|
CSS_PATH = "binding01.css"
|
|
BINDINGS = [
|
|
("r", "add_bar('red')", "Add Red"),
|
|
("g", "add_bar('green')", "Add Green"),
|
|
("b", "add_bar('blue')", "Add Blue"),
|
|
]
|
|
|
|
def compose(self) -> ComposeResult:
|
|
yield Footer()
|
|
|
|
def action_add_bar(self, color: str) -> None:
|
|
bar = Bar(color)
|
|
bar.styles.background = Color.parse(color).with_alpha(0.5)
|
|
self.mount(bar)
|
|
self.call_later(self.screen.scroll_end, animate=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = BindingApp()
|
|
app.run()
|