-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify wording, add counter example
- Loading branch information
1 parent
3e1b413
commit 0fb0e2b
Showing
2 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.binding import Binding | ||
from textual.reactive import reactive | ||
from textual.widgets import Static | ||
|
||
|
||
class Counter(Static, can_focus=True): | ||
"""A counter that can be incremented and decremented by pressing keys.""" | ||
|
||
BINDINGS = [ | ||
Binding("up", "change_count(1)", "Increment"), | ||
Binding("down", "change_count(-1)", "Decrement"), | ||
] | ||
|
||
count = reactive(0) | ||
|
||
def render(self) -> str: | ||
return f"Count: {self.count}" | ||
|
||
def action_change_count(self, amount: int) -> None: | ||
self.count += amount | ||
|
||
|
||
class CalculatorApp(App[None]): | ||
def compose(self) -> ComposeResult: | ||
yield Counter() | ||
yield Counter() | ||
|
||
|
||
if __name__ == "__main__": | ||
app = CalculatorApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters