|
| 1 | +# from textual import on |
| 2 | +from textual.app import App |
| 3 | +from textual.widgets import Button, Digits, Footer |
| 4 | + |
| 5 | +class EventsApp(App): |
| 6 | + CSS_PATH = "events.tcss" |
| 7 | + BINDINGS = [ |
| 8 | + ("q", "quit", "Quit"), |
| 9 | + ("b", "toggle_border", "Toggle border"), |
| 10 | + ] |
| 11 | + |
| 12 | + presses_count = 0 |
| 13 | + double_border = False |
| 14 | + |
| 15 | + def compose(self): |
| 16 | + yield Button( |
| 17 | + "Click me!", |
| 18 | + id="button", |
| 19 | + ) |
| 20 | + digits = Digits("0", id="digits") |
| 21 | + digits.border_subtitle = "Button presses" |
| 22 | + yield digits |
| 23 | + yield Footer() |
| 24 | + |
| 25 | + def action_toggle_border(self): |
| 26 | + self.double_border = not self.double_border |
| 27 | + digits = self.query_one("#digits") |
| 28 | + if self.double_border: |
| 29 | + digits.styles.border = ("double", "yellow") |
| 30 | + else: |
| 31 | + digits.styles.border = ("solid", "white") |
| 32 | + |
| 33 | + def on_button_pressed(self, event): |
| 34 | + if event.button.id == "button": |
| 35 | + self.presses_count += 1 |
| 36 | + digits = self.query_one("#digits") |
| 37 | + digits.update(f"{self.presses_count}") |
| 38 | + |
| 39 | + # @on(Button.Pressed, "#button") |
| 40 | + # def button_pressed(self, event): |
| 41 | + # self.presses_count += 1 |
| 42 | + # digits = self.query_one("#digits") |
| 43 | + # digits.update(f"{self.presses_count}") |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + app = EventsApp() |
| 47 | + app.run() |
0 commit comments