File size: 846 Bytes
2c3c408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from textual import events
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Button


class ButtonsApp(App[str]):
    def compose(self) -> ComposeResult:
        yield Vertical(
            Button("default", id="foo"),
            Button.success("success", id="bar"),
            Button.warning("warning", id="baz"),
            Button.error("error", id="baz"),
        )

    def on_button_pressed(self, event: Button.Pressed) -> None:
        self.app.bell()

    async def on_key(self, event: events.Key) -> None:
        await self.dispatch_key(event)

    def key_d(self):
        self.dark = not self.dark


app = ButtonsApp(
    log_path="textual.log",
    css_path="buttons.css",
    watch_css=True,
)

if __name__ == "__main__":
    result = app.run()
    print(repr(result))