Dialog classes#
These are the dialog classes behind the Messagebox
and Querybox facades. Use them directly when
you need full control over a dialog, or subclass Dialog to build your own.
Dialog#
Dialog is the base for custom dialogs. Subclass it and implement
create_body() and create_buttonbox(), set self._result,
then call show(); the outcome is read from result after
show returns.
Options#
Construct with Dialog(parent=None, title="", alert=False).
Option |
Type |
Description |
|---|---|---|
|
|
The window to center over and block while open. Defaults to the application root. |
|
|
The text shown on the dialog’s title bar. |
|
|
Ring the display bell when the dialog appears. |
Methods#
- show(position=None, wait_for_result=True)
Build and display the dialog modally.
- Parameters:
position – An
(x, y)top-left screen position. Centered onparentby default.wait_for_result – Block until the dialog is closed. Default
True.
- Returns:
None. Readresultafter it returns.
- build()
Construct the dialog window and its body and button box. Called by
show().- Returns:
None.
- close()
Close the dialog and release its grab.
- Returns:
None.
- create_body(master)
Override hook. Subclasses build the dialog’s body widgets here.
- Parameters:
master – The parent widget for the body content.
- Returns:
None.
- create_buttonbox(master)
Override hook. Subclasses build the button row here.
- Parameters:
master – The parent widget for the button box.
- Returns:
None.
- result
The dialog’s outcome, set by the subclass. Read it after
show()returns.
MessageDialog#
MessageDialog is a configurable message dialog — the class
Messagebox builds. Use it directly for
custom button sets and colors.
Options#
Construct with MessageDialog(message, title=" ", buttons=None, command=None,
width=50, parent=None, alert=False, default=None, padding=(20, 20), icon=None).
Option |
Type |
Description |
|---|---|---|
|
|
The message text. |
|
|
The text shown on the dialog’s title bar. |
|
|
The button labels, each optionally |
|
|
A callback invoked when a button is pressed. |
|
|
The message wrap width in characters. |
|
|
The window to center over and block while open. |
|
|
Ring the display bell when the dialog appears. |
|
|
The label of the button focused by default. |
|
|
Padding around the content. |
|
|
A Bootstrap Icons glyph name shown beside the message. |
Methods#
- show(position=None, wait_for_result=True)
Build and display the dialog modally.
- Parameters:
position – An
(x, y)top-left screen position. Centered onparentby default.wait_for_result – Block until the dialog is closed. Default
True.
- Returns:
None. Readresultafter it returns.
- result
The clicked button’s text, or
Noneif the dialog is closed.
QueryDialog#
QueryDialog is a configurable input dialog — the class
Querybox builds. It collects a typed value,
or a choice from a list.
Options#
Construct with QueryDialog(prompt, title=" ", initialvalue="", minvalue=None,
maxvalue=None, width=65, datatype=str, padding=(20, 20), parent=None,
items=None).
Option |
Type |
Description |
|---|---|---|
|
|
The label shown above the input. |
|
|
The text shown on the dialog’s title bar. |
|
|
The value the input starts with. |
|
|
The smallest accepted value (numeric datatypes). |
|
|
The largest accepted value (numeric datatypes). |
|
|
The entry width in characters. |
|
|
The type the input is validated and cast to ( |
|
|
Padding around the content. |
|
|
The window to center over and block while open. |
|
|
If given, the user chooses from this list instead of typing. |
Methods#
- show(position=None, wait_for_result=True)
Build and display the dialog modally.
- Parameters:
position – An
(x, y)top-left screen position. Centered onparentby default.wait_for_result – Block until the dialog is closed. Default
True.
- Returns:
None. Readresultafter it returns.
- result
The entered or chosen value cast to
datatype, orNoneif cancelled.
- validate()
Called when the user submits, before the dialog closes. The default checks the
datatypecast, theminvalue/maxvaluerange, and membership initems; override it in a subclass to add your own checks.- Returns:
Trueto accept and close;Falseto keep the dialog open.- Return type:
- apply()
Called after a validated submit closes the dialog (a no-op by default). Override it in a subclass to process the result.
- Returns:
None.
See also#
Dialogs — how to use them, with examples.
Messagebox — the message-dialog facade.
Querybox — the input-and-picker facade.