dialog
pdwidgets.widgets.dialog
Modal dialog widget.
Dialog(parent, message='', title=None, buttons=None, on_result=None, fg=None, bg=None, w=None, h=None, font=None, scrim=None)
Bases: Widget
Modal message box with title, body, and action buttons.
Initialize a Dialog: a modal message box centered over the screen.
The dialog is a full-screen overlay (painted with an opaque scrim —
the pure-Python framebuffer has no alpha blending, so the backdrop is a
solid muted color rather than a translucent dim) holding a centered
:class:Card with a title, a message and one or more action buttons.
While shown it grabs modal pointer capture so the underlying UI is inert.
Clicking a button closes the dialog and invokes on_result with that
button's label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Widget
|
The parent widget or screen; the overlay is attached to the root screen so it covers the whole display. |
required |
message
|
str
|
The message body text. |
''
|
title
|
str
|
Optional title shown at the top of the card. |
None
|
buttons
|
list
|
Button labels (default |
None
|
on_result
|
callable
|
Called as |
None
|
fg
|
int
|
Text color; defaults to |
None
|
bg
|
int
|
Card color; defaults to |
None
|
w
|
int
|
Card width (auto-sized when omitted). |
None
|
h
|
int
|
Card height (auto-sized when omitted). |
None
|
font
|
module
|
Optional proportional font module for the title. |
None
|
scrim
|
int
|
Backdrop fill color; defaults to |
None
|
Usage
dlg = Dialog(screen, "Power off?", title="Confirm", buttons=["Cancel", "OK"], on_result=handle) dlg.show()
draw(area=None)
Paint the opaque scrim behind the card.
A full draw fills the whole screen; a child's parent.draw(child.area)
request fills just that sub-region with the scrim so the card's children
are not erased.
hide_dialog()
Hide the dialog and release modal pointer capture.
show()
Show the dialog and grab modal pointer capture.