watch_ method not working with dict
See original GitHub issueSorry if the title is off. I’m having a hard time getting watch_
methods working with dict
attributes. Here’s an example:
from json import dumps
from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widgets import Input, Static
class Example(App):
display = reactive({"input": ""})
def compose(self) -> ComposeResult:
yield Input()
yield Static()
def on_input_changed(self, event: Input.Changed) -> None:
self.display["input"] = event.value
def watch_display(self, new_display: dict) -> None:
self.query_one(Static).update(dumps(new_display))
Example().run()
As I type in the Input
, the Static
’s content doesn’t update. Interestingly, if I swap json.dumps()
for rich.Pretty()
, it does update, but only after I move the mouse over it. The only way I’ve been able to get what I want is by moving the update()
into the on_input_changed()
handler.
def on_input_changed(self, event: Input.Changed) -> None:
self.display["input"] = event.value
self.query_one(Static).update(dumps(self.display))
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
xcode - Passing Dictionary to Watch - Stack Overflow
I'm trying to pass data from iPhone -> Watch via Watch Connectivity using background transfer via Application Context method. iPhone ...
Read more >Dictionaries in Python - Real Python
In this Python dictionaries tutorial, you'll cover the basic characteristics and learn how to access and manage dictionary data. Once you have finished...
Read more >Python 3.7: How To Use The Dict() Built-in Function - YouTube
In this Python 3.7 tutorial, we will show you how to use the dict () built-in function to create a dictionary. For more...
Read more >How to pass a dict when a Python function expects **kwargs
Many Python functions have a **kwargs parameter — a dict whose keys and values are populated via keyword arguments. But what if you...
Read more >Fix TypeError: ' ' not supported between instances of 'dict' and ...
5.2K views 1 year ago Troubleshooting ... not supported between instances of ' dict ' and ' dict ' when your trying to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Aye, it’s fine to close if you’re happy with that.
Ahh, okay, really appreciate the writeup! I thought maybe that was the case with
dict
, but seeing thePretty()
update had me convinced that it was at least partially working. Thanks again, really been enjoying learning and working with all the new capability.