Skip to content

MessageDialog

A simple modal dialog class that can be used to build simple message dialogs.

Displays a message and a set of buttons. Each of the buttons in the message window is identified by a unique symbolic name. After the message window is popped up, the message box awaits for the user to select one of the buttons. Then it returns the symbolic name of the selected button. Use a Toplevel widget for more advanced modal dialog designs.

Events

<<DialogResult>>: Fired when dialog closes. Provides event.data with keys: result (str), confirmed (bool).

result property

result: Any

The dialog result value (the text of the button pressed).

__init__

__init__(
    message: str,
    title: str = " ",
    buttons: Optional[List[str]] = None,
    command: Optional[Callable[[], None]] = None,
    width: int = 50,
    master: Optional[Misc] = None,
    alert: bool = False,
    default: Optional[str] = None,
    padding: tuple[int, int] | int = (20, 20),
    icon: Optional[str | dict] = None,
    **kwargs: Any,
) -> None

Create a message dialog.

Parameters:

Name Type Description Default
message str

The message text to display. Supports multiline strings.

required
title str

The dialog window title.

' '
buttons Optional[List[str]]

List of button labels. Can specify color as "label:color". If None, defaults to ["Cancel", "OK"]. Legacy "bootstyle" syntax is still supported (e.g., "OK:primary").

None
command Optional[Callable[[], None]]

Optional callback function to execute when any button is pressed.

None
width int

Maximum width in characters for text wrapping.

50
master Optional[Misc]

Parent widget for the dialog.

None
alert bool

If True, rings the system bell when shown.

False
default Optional[str]

The button label to use as default. Receives primary bootstyle and focus.

None
padding tuple[int, int] | int

Padding around the message content.

(20, 20)
icon Optional[str | dict]

Optional icon specification. Can be a string (icon name) or dict with keys: 'name' (required), 'size' (default 32), 'color' (optional).

None
**kwargs Any

Additional keyword arguments. Supports 'localize' to enable translation.

{}

show

show(position: Optional[tuple[int, int]] = None) -> None

Show the dialog.

Parameters:

Name Type Description Default
position Optional[tuple[int, int]]

x and y coordinates to position the dialog. If None, centers on parent.

None

on_dialog_result

on_dialog_result(
    callback: Callable[[Any], None],
) -> Optional[str]

Bind a callback fired when the dialog produces a result.

The callback receives event.data["result"] when available.

Parameters:

Name Type Description Default
callback Callable[[Any], None]

Callable that receives the result payload.

required

Returns:

Type Description
Optional[str]

Binding identifier for use with off_dialog_result.

off_dialog_result

off_dialog_result(funcid: str) -> None

Unbind a previously bound dialog result callback.