|
11 | 11 |
|
12 | 12 | The :mod:`tkinter.messagebox` module provides a template base class as well as
|
13 | 13 | a variety of convenience methods for commonly used configurations. The message
|
14 |
| -boxes are modal and will return a subset of (True, False, OK, None, Yes, No) based on |
| 14 | +boxes are modal and will return a subset of (``True``, ``False``, ``None``, |
| 15 | +:data:`OK`, :data:`CANCEL`, :data:`YES`, :data:`NO`) based on |
15 | 16 | the user's selection. Common message box styles and layouts include but are not
|
16 | 17 | limited to:
|
17 | 18 |
|
18 | 19 | .. figure:: tk_msg.png
|
19 | 20 |
|
20 | 21 | .. class:: Message(master=None, **options)
|
21 | 22 |
|
22 |
| - Create a default information message box. |
| 23 | + Create a message window with an application-specified message, an icon |
| 24 | + and a set of buttons. |
| 25 | + Each of the buttons in the message window is identified by a unique symbolic name (see the *type* options). |
| 26 | + |
| 27 | + The following options are supported: |
| 28 | + |
| 29 | + *command* |
| 30 | + Specifies the function to invoke when the user closes the dialog. |
| 31 | + The name of the button clicked by the user to close the dialog is |
| 32 | + passed as argument. |
| 33 | + This is only available on macOS. |
| 34 | + |
| 35 | + *default* |
| 36 | + Gives the :ref:`symbolic name <messagebox-buttons>` of the default button |
| 37 | + for this message window (:data:`OK`, :data:`CANCEL`, and so on). |
| 38 | + If this option is not specified, the first button in the dialog will |
| 39 | + be made the default. |
| 40 | + |
| 41 | + *detail* |
| 42 | + Specifies an auxiliary message to the main message given by the |
| 43 | + *message* option. |
| 44 | + The message detail will be presented beneath the main message and, |
| 45 | + where supported by the OS, in a less emphasized font than the main |
| 46 | + message. |
| 47 | + |
| 48 | + *icon* |
| 49 | + Specifies an :ref:`icon <messagebox-icons>` to display. |
| 50 | + If this option is not specified, then the :data:`INFO` icon will be |
| 51 | + displayed. |
| 52 | + |
| 53 | + *message* |
| 54 | + Specifies the message to display in this message box. |
| 55 | + The default value is an empty string. |
| 56 | + |
| 57 | + *parent* |
| 58 | + Makes the specified window the logical parent of the message box. |
| 59 | + The message box is displayed on top of its parent window. |
| 60 | + |
| 61 | + *title* |
| 62 | + Specifies a string to display as the title of the message box. |
| 63 | + This option is ignored on macOS, where platform guidelines forbid |
| 64 | + the use of a title on this kind of dialog. |
| 65 | + |
| 66 | + *type* |
| 67 | + Arranges for a :ref:`predefined set of buttons <messagebox-types>` |
| 68 | + to be displayed. |
| 69 | + |
| 70 | + .. method:: show(**options) |
| 71 | + |
| 72 | + Display a message window and wait for the user to select one of the buttons. Then return the symbolic name of the selected button. |
| 73 | + Keyword arguments can override options specified in the constructor. |
| 74 | + |
23 | 75 |
|
24 | 76 | **Information message box**
|
25 | 77 |
|
26 |
| -.. method:: showinfo(title=None, message=None, **options) |
| 78 | +.. function:: showinfo(title=None, message=None, **options) |
| 79 | + |
| 80 | + Creates and displays an information message box with the specified title |
| 81 | + and message. |
27 | 82 |
|
28 | 83 | **Warning message boxes**
|
29 | 84 |
|
30 |
| -.. method:: showwarning(title=None, message=None, **options) |
31 |
| - showerror(title=None, message=None, **options) |
| 85 | +.. function:: showwarning(title=None, message=None, **options) |
| 86 | + |
| 87 | + Creates and displays a warning message box with the specified title |
| 88 | + and message. |
| 89 | + |
| 90 | +.. function:: showerror(title=None, message=None, **options) |
| 91 | + |
| 92 | + Creates and displays an error message box with the specified title |
| 93 | + and message. |
32 | 94 |
|
33 | 95 | **Question message boxes**
|
34 | 96 |
|
35 |
| -.. method:: askquestion(title=None, message=None, **options) |
36 |
| - askokcancel(title=None, message=None, **options) |
37 |
| - askretrycancel(title=None, message=None, **options) |
38 |
| - askyesno(title=None, message=None, **options) |
39 |
| - askyesnocancel(title=None, message=None, **options) |
| 97 | +.. function:: askquestion(title=None, message=None, *, type=YESNO, **options) |
| 98 | + |
| 99 | + Ask a question. By default shows buttons :data:`YES` and :data:`NO`. |
| 100 | + Returns the symbolic name of the selected button. |
| 101 | + |
| 102 | +.. function:: askokcancel(title=None, message=None, **options) |
| 103 | + |
| 104 | + Ask if operation should proceed. Shows buttons :data:`OK` and :data:`CANCEL`. |
| 105 | + Returns ``True`` if the answer is ok and ``False`` otherwise. |
| 106 | + |
| 107 | +.. function:: askretrycancel(title=None, message=None, **options) |
| 108 | + |
| 109 | + Ask if operation should be retried. Shows buttons :data:`RETRY` and :data:`CANCEL`. |
| 110 | + Return ``True`` if the answer is yes and ``False`` otherwise. |
| 111 | + |
| 112 | +.. function:: askyesno(title=None, message=None, **options) |
| 113 | + |
| 114 | + Ask a question. Shows buttons :data:`YES` and :data:`NO`. |
| 115 | + Returns ``True`` if the answer is yes and ``False`` otherwise. |
| 116 | + |
| 117 | +.. function:: askyesnocancel(title=None, message=None, **options) |
| 118 | + |
| 119 | + Ask a question. Shows buttons :data:`YES`, :data:`NO` and :data:`CANCEL`. |
| 120 | + Return ``True`` if the answer is yes, ``None`` if cancelled, and ``False`` |
| 121 | + otherwise. |
| 122 | + |
| 123 | + |
| 124 | +.. _messagebox-buttons: |
| 125 | + |
| 126 | +Symbolic names of buttons: |
| 127 | + |
| 128 | +.. data:: ABORT |
| 129 | + :value: 'abort' |
| 130 | +.. data:: RETRY |
| 131 | + :value: 'retry' |
| 132 | +.. data:: IGNORE |
| 133 | + :value: 'ignore' |
| 134 | +.. data:: OK |
| 135 | + :value: 'ok' |
| 136 | +.. data:: CANCEL |
| 137 | + :value: 'cancel' |
| 138 | +.. data:: YES |
| 139 | + :value: 'yes' |
| 140 | +.. data:: NO |
| 141 | + :value: 'no' |
| 142 | + |
| 143 | +.. _messagebox-types: |
| 144 | + |
| 145 | +Predefined sets of buttons: |
| 146 | + |
| 147 | +.. data:: ABORTRETRYIGNORE |
| 148 | + :value: 'abortretryignore' |
| 149 | + |
| 150 | + Displays three buttons whose symbolic names are :data:`ABORT`, |
| 151 | + :data:`RETRY` and :data:`IGNORE`. |
| 152 | + |
| 153 | +.. data:: OK |
| 154 | + :value: 'ok' |
| 155 | + :noindex: |
| 156 | + |
| 157 | + Displays one button whose symbolic name is :data:`OK`. |
| 158 | + |
| 159 | +.. data:: OKCANCEL |
| 160 | + :value: 'okcancel' |
| 161 | + |
| 162 | + Displays two buttons whose symbolic names are :data:`OK` and |
| 163 | + :data:`CANCEL`. |
| 164 | + |
| 165 | +.. data:: RETRYCANCEL |
| 166 | + :value: 'retrycancel' |
| 167 | + |
| 168 | + Displays two buttons whose symbolic names are :data:`RETRY` and |
| 169 | + :data:`CANCEL`. |
| 170 | + |
| 171 | +.. data:: YESNO |
| 172 | + :value: 'yesno' |
| 173 | + |
| 174 | + Displays two buttons whose symbolic names are :data:`YES` and |
| 175 | + :data:`NO`. |
| 176 | + |
| 177 | +.. data:: YESNOCANCEL |
| 178 | + :value: 'yesnocancel' |
| 179 | + |
| 180 | + Displays three buttons whose symbolic names are :data:`YES`, |
| 181 | + :data:`NO` and :data:`CANCEL`. |
| 182 | + |
| 183 | +.. _messagebox-icons: |
| 184 | + |
| 185 | +Icon images: |
| 186 | + |
| 187 | +.. data:: ERROR |
| 188 | + :value: 'error' |
| 189 | +.. data:: INFO |
| 190 | + :value: 'info' |
| 191 | +.. data:: QUESTION |
| 192 | + :value: 'question' |
| 193 | +.. data:: WARNING |
| 194 | + :value: 'warning' |
0 commit comments