Debian Codegraph @

Doc/library/tkinter.messagebox.rst

raw
1 :mod:`!tkinter.messagebox` --- Tkinter message prompts
2 ======================================================
3
4 .. module:: tkinter.messagebox
5 :synopsis: Various types of alert dialogs
6
7 **Source code:** :source:`Lib/tkinter/messagebox.py`
8
9 --------------
10
11 The :mod:`!tkinter.messagebox` module provides a template base class as well as
12 a variety of convenience methods for commonly used configurations.
13 The message boxes are modal: each blocks until the user responds, then returns
14 a value that depends on the function.
15 The ``show*`` functions and :meth:`Message.show` return the symbolic name of
16 the button the user pressed, as a string (such as :data:`OK` or :data:`YES`).
17 Common message box styles and layouts include but are not limited to:
18
19 .. figure:: tk_msg.png
20
21 .. class:: Message(master=None, **options)
22
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 .. note::
71
72 Tk 8.6 added the *command* option.
73
74 .. method:: show(**options)
75
76 Display a message window and wait for the user to select one of the buttons. Then return the symbolic name of the selected button.
77 Keyword arguments can override options specified in the constructor.
78
79
80 **Information message box**
81
82 .. function:: showinfo(title=None, message=None, **options)
83
84 Creates and displays an information message box with the specified title
85 and message.
86
87 **Warning message boxes**
88
89 .. function:: showwarning(title=None, message=None, **options)
90
91 Creates and displays a warning message box with the specified title
92 and message.
93
94 .. function:: showerror(title=None, message=None, **options)
95
96 Creates and displays an error message box with the specified title
97 and message.
98
99 **Question message boxes**
100
101 .. function:: askquestion(title=None, message=None, *, type=YESNO, **options)
102
103 Ask a question. By default shows buttons :data:`YES` and :data:`NO`.
104 Returns the symbolic name of the selected button.
105
106 .. function:: askokcancel(title=None, message=None, **options)
107
108 Ask if operation should proceed. Shows buttons :data:`OK` and :data:`CANCEL`.
109 Returns ``True`` if the answer is ok and ``False`` otherwise.
110
111 .. function:: askretrycancel(title=None, message=None, **options)
112
113 Ask if operation should be retried. Shows buttons :data:`RETRY` and :data:`CANCEL`.
114 Return ``True`` if the answer is retry and ``False`` otherwise.
115
116 .. function:: askyesno(title=None, message=None, **options)
117
118 Ask a question. Shows buttons :data:`YES` and :data:`NO`.
119 Returns ``True`` if the answer is yes and ``False`` otherwise.
120
121 .. function:: askyesnocancel(title=None, message=None, **options)
122
123 Ask a question. Shows buttons :data:`YES`, :data:`NO` and :data:`CANCEL`.
124 Return ``True`` if the answer is yes, ``None`` if cancelled, and ``False``
125 otherwise.
126
127
128 .. _messagebox-buttons:
129
130 Symbolic names of buttons:
131
132 .. data:: ABORT
133 :value: 'abort'
134 .. data:: RETRY
135 :value: 'retry'
136 .. data:: IGNORE
137 :value: 'ignore'
138 .. data:: OK
139 :value: 'ok'
140 .. data:: CANCEL
141 :value: 'cancel'
142 .. data:: YES
143 :value: 'yes'
144 .. data:: NO
145 :value: 'no'
146
147 .. _messagebox-types:
148
149 Predefined sets of buttons:
150
151 .. data:: ABORTRETRYIGNORE
152 :value: 'abortretryignore'
153
154 Displays three buttons whose symbolic names are :data:`ABORT`,
155 :data:`RETRY` and :data:`IGNORE`.
156
157 .. data:: OK
158 :value: 'ok'
159 :noindex:
160
161 Displays one button whose symbolic name is :data:`OK`.
162
163 .. data:: OKCANCEL
164 :value: 'okcancel'
165
166 Displays two buttons whose symbolic names are :data:`OK` and
167 :data:`CANCEL`.
168
169 .. data:: RETRYCANCEL
170 :value: 'retrycancel'
171
172 Displays two buttons whose symbolic names are :data:`RETRY` and
173 :data:`CANCEL`.
174
175 .. data:: YESNO
176 :value: 'yesno'
177
178 Displays two buttons whose symbolic names are :data:`YES` and
179 :data:`NO`.
180
181 .. data:: YESNOCANCEL
182 :value: 'yesnocancel'
183
184 Displays three buttons whose symbolic names are :data:`YES`,
185 :data:`NO` and :data:`CANCEL`.
186
187 .. _messagebox-icons:
188
189 Icon images:
190
191 .. data:: ERROR
192 :value: 'error'
193 .. data:: INFO
194 :value: 'info'
195 .. data:: QUESTION
196 :value: 'question'
197 .. data:: WARNING
198 :value: 'warning'