-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_bind.py
35 lines (22 loc) · 860 Bytes
/
data_bind.py
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.app import App, ComposeResult
from textual.reactive import reactive
from textual.widget import Widget
from textual.widgets import Label
class L3(Widget):
animal_sound = reactive("Meow")
def compose(self) -> ComposeResult:
yield Label(id="label3")
def watch_animal_sound(self, value: str) -> None:
self.query_one("#label3").update(self.animal_sound * 3)
class L2(Widget):
animal_sound = reactive("Woof")
def compose(self) -> ComposeResult:
yield Label(id="label2")
yield L3().data_bind(L2.animal_sound)
def watch_animal_sound(self, value: str) -> None:
self.query_one("#label2").update(self.animal_sound * 2)
class MainApp(App):
animal_sound = reactive("Meh")
def compose(self) -> ComposeResult:
yield L2().data_bind(MainApp.animal_sound)
MainApp().run()