mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
38 lines
994 B
Python
38 lines
994 B
Python
from textual.app import App, ComposeResult
|
|
from textual.containers import Grid
|
|
from textual.screen import Screen
|
|
from textual.widgets import Static, Header, Footer, Button
|
|
|
|
|
|
class QuitScreen(Screen):
|
|
def compose(self) -> ComposeResult:
|
|
yield Grid(
|
|
Static("Are you sure you want to quit?", id="question"),
|
|
Button("Quit", variant="error", id="quit"),
|
|
Button("Cancel", variant="primary", id="cancel"),
|
|
id="dialog",
|
|
)
|
|
|
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
if event.button.id == "quit":
|
|
self.app.exit()
|
|
else:
|
|
self.app.pop_screen()
|
|
|
|
|
|
class ModalApp(App):
|
|
CSS_PATH = "modal01.css"
|
|
BINDINGS = [("q", "request_quit", "Quit")]
|
|
|
|
def compose(self) -> ComposeResult:
|
|
yield Header()
|
|
yield Footer()
|
|
|
|
def action_request_quit(self) -> None:
|
|
self.push_screen(QuitScreen())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = ModalApp()
|
|
app.run()
|