Skip to content

Returning integer data from a modal screen. #5388

Answered by TomJGooding
wiredworm asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a quick recap of how to return data from screens from the docs:

To return data from a screen, call dismiss() on the screen with the data you wish to return. This will pop the screen and invoke a callback set when the screen was pushed (with push_screen).

For example:

from textual.app import App, ComposeResult
from textual.screen import ModalScreen
from textual.validation import Integer
from textual.widgets import Input


class ExampleScreen(ModalScreen[int]):
    def compose(self) -> ComposeResult:
        yield Input(validators=Integer())

    def on_input_submitted(self, event: Input.Submitted) -> None:
        if event.validation_result.is_valid:  # type: ignore[union-attr]

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wiredworm
Comment options

Answer selected by wiredworm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants