MessageDialog
Bases: Dialog
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.
Source code in src/ttkbootstrap/dialogs/message.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
__init__(message, title=' ', buttons=None, command=None, width=50, parent=None, alert=False, default=None, padding=(20, 20), icon=None, **kwargs)
Create a message dialog.
Parameters:
message (str):
The message text to display. Supports multiline strings
(separated by \n).
title (str):
The dialog window title (default=' ').
buttons (List[str]):
List of button labels. Each button can optionally specify
a bootstyle using "label:bootstyle" format (e.g., "OK:primary").
If None, defaults to ["Cancel", "OK"]. The buttons are
displayed in reverse order (rightmost first).
command (Callable):
Optional callback function to execute when a button is pressed.
width (int):
Maximum width in characters for text wrapping (default=50).
parent (Widget):
Parent widget. The dialog will be centered on this widget.
alert (bool):
If True, rings the system bell when the dialog is shown
(default=False).
default (str):
The button label to use as the default (receives primary
bootstyle and initial focus). If None, the rightmost button
becomes the default.
padding (int | tuple):
Padding around the message content. Can be a single int or
tuple (horizontal, vertical) (default=(20, 20)).
icon (str):
Optional icon to display. Can be image data, file path,
or Icon constant (e.g., Icon.info).
**kwargs (Dict):
Additional keyword arguments. Supports 'localize' (bool)
to enable message translation.
Source code in src/ttkbootstrap/dialogs/message.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
create_body(master)
Overrides the parent method; adds the message section.
Source code in src/ttkbootstrap/dialogs/message.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
create_buttonbox(master)
Overrides the parent method; adds the message buttonbox
Source code in src/ttkbootstrap/dialogs/message.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
on_button_press(button)
Save result, destroy the toplevel, and execute command.
Source code in src/ttkbootstrap/dialogs/message.py
184 185 186 187 188 189 190 | |
show(position=None, wait_for_result=True)
Create and display the popup messagebox.
Source code in src/ttkbootstrap/dialogs/message.py
192 193 194 | |