Skip to content

Commit 6382685

Browse files
committed
Simplify and use RenderResult over str
1 parent 3c8f567 commit 6382685

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

docs/examples/guide/widgets/counter01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from textual.app import App, ComposeResult
1+
from textual.app import App, ComposeResult, RenderResult
22
from textual.reactive import reactive
33
from textual.widgets import Footer, Static
44

@@ -8,7 +8,7 @@ class Counter(Static, can_focus=True): # (1)!
88

99
count = reactive(0)
1010

11-
def render(self) -> str:
11+
def render(self) -> RenderResult:
1212
return f"Count: {self.count}"
1313

1414

docs/examples/guide/widgets/counter02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from textual.app import App, ComposeResult
1+
from textual.app import App, ComposeResult, RenderResult
22
from textual.reactive import reactive
33
from textual.widgets import Footer, Static
44

@@ -13,7 +13,7 @@ class Counter(Static, can_focus=True):
1313

1414
count = reactive(0)
1515

16-
def render(self) -> str:
16+
def render(self) -> RenderResult:
1717
return f"Count: {self.count}"
1818

1919
def action_change_count(self, amount: int):

docs/guide/widgets.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ A widget is only be able to handle key presses if it or one of its descendants h
200200
To demonstrate, let's design a simple interactive counter widget which can be incremented and decremented using the keyboard.
201201

202202
In the following example, we define a simple `Counter` widget with `can_focus=True`, and some CSS to make it stand out when focused.
203-
Our app contains three `Counter` widgets, which we can move focus between using ++tab++ and ++shift+tab++.
203+
Our app contains three `Counter` widgets, which we can focus by clicking or using ++tab++ and ++shift+tab++.
204204

205205
=== "counter01.py"
206206

@@ -223,12 +223,6 @@ Our app contains three `Counter` widgets, which we can move focus between using
223223
```{.textual path="docs/examples/guide/widgets/counter01.py"}
224224
```
225225

226-
Notice that Textual automatically focused the first widget, and that pressing ++tab++ and ++shift+tab++ will move focus between widgets.
227-
228-
!!! note
229-
230-
You can also move focus to a widget by clicking on it.
231-
232226
Now that our counter is focusable, let's make it interactive by adding some key bindings and actions to it.
233227
To do this, we add a `BINDINGS` class variable to `Counter`, with bindings for ++up++ and ++down++.
234228
These new bindings are linked to the `change_count` action, which updates the `count` reactive attribute.

0 commit comments

Comments
 (0)