Dismiss the screen, optionally with a result. Any callback provided in [push_screen][textual.app.App.push_screen] will be invoked with the supplied result. !!! warning Textual will raise a [`ScreenError`][textual.app.ScreenError] if you await the return value from a
(self, result: ScreenResultType | None = None)
| 2046 | self.selections = selections |
| 2047 | |
| 2048 | def dismiss(self, result: ScreenResultType | None = None) -> AwaitComplete: |
| 2049 | """Dismiss the screen, optionally with a result. |
| 2050 | |
| 2051 | Any callback provided in [push_screen][textual.app.App.push_screen] will be invoked with the supplied result. |
| 2052 | |
| 2053 | !!! warning |
| 2054 | |
| 2055 | Textual will raise a [`ScreenError`][textual.app.ScreenError] if you await the return value from a |
| 2056 | message handler on the Screen being dismissed. If you want to dismiss the current screen, you can |
| 2057 | call `self.dismiss()` _without_ awaiting. |
| 2058 | |
| 2059 | Args: |
| 2060 | result: The optional result to be passed to the result callback. |
| 2061 | |
| 2062 | """ |
| 2063 | _rich_traceback_omit = True |
| 2064 | if self._result_callbacks: |
| 2065 | callback = self._result_callbacks[-1] |
| 2066 | callback(result) |
| 2067 | await_pop = self.app.pop_screen() |
| 2068 | |
| 2069 | def pre_await() -> None: |
| 2070 | """Called by the AwaitComplete object.""" |
| 2071 | _rich_traceback_omit = True |
| 2072 | if active_message_pump.get() is self: |
| 2073 | from textual.app import ScreenError |
| 2074 | |
| 2075 | raise ScreenError( |
| 2076 | "Can't await screen.dismiss() from the screen's message handler; try removing the await keyword." |
| 2077 | ) |
| 2078 | |
| 2079 | await_pop.set_pre_await_callback(pre_await) |
| 2080 | |
| 2081 | return await_pop |
| 2082 | |
| 2083 | def pop_until_active(self) -> None: |
| 2084 | """Pop any screens on top of this one, until this screen is active. |