Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Add an example of screen callbacks working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Jun 16, 2024
1 parent e4793ea commit 13ace2f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions screen_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Evidence that screen callbacks are still working.
For a reply to https://github.com/Textualize/textual/issues/4656.
"""

from textual import on
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Button


class Test(Screen[str]):
def compose(self) -> ComposeResult:
yield Button("Yes", id="Yes")
yield Button("No", id="No")

@on(Button.Pressed)
def test_the_callback(self, event: Button.Pressed) -> None:
assert event.button.id is not None
self.dismiss(event.button.id)


class ScreenCallbackTest(App[None]):
def compose(self) -> ComposeResult:
yield Button("Test")

@on(Button.Pressed)
def test_screen_callback(self) -> None:
def show_result(result: str) -> None:
self.notify(result)

self.push_screen(Test(), callback=show_result)


if __name__ == "__main__":
ScreenCallbackTest().run()

### screen_callback.py ends here

0 comments on commit 13ace2f

Please sign in to comment.