-
I'm using Textual 0.25.0. I have two screens with each having a single The problem is I can't identify I'm not sure if I'm even trying to tackle this with the right approach, so any advice would be very welcome. Here's my example code: from textual.app import App, ComposeResult
from textual import events
from textual.screen import Screen
from textual.widgets import Static
class TextOne(Static):
pass
class TextTwo(Static):
pass
class ScreenOne(Screen):
def compose(self) -> ComposeResult:
yield TextOne("Press Enter to update text on ScreenTwo through a function.")
def on_key(self, event: events.Key) -> None:
if event.key == "enter":
app.push_screen("two")
app.query_one("ScreenTwo").displayinfo()
class ScreenTwo(Screen):
def displayinfo(self):
"""A function that does something complicated and displays the result."""
app.log(app.tree)
app.query_one("TextTwo").update("New text on ScreenTwo.")
class App(App):
SCREENS = {"one": ScreenOne(), "two": ScreenTwo()}
def on_mount(self) -> None:
app.push_screen("one")
app = App()
app.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Your |
Beta Was this translation helpful? Give feedback.
I've managed to figure it out eventually.
As I mentioned in my previous reply, I can confirm that calling
display_info
fromon_mount
works in the minimal example.Now, in my Syncthing project, I had to cut
query_one
from thewatch
method and (still within the second screen) move it insideon_mount
. I still don't understand fully why this is needed, but I no longer receive the error.Anyway, thank you for your help!