mirror of
https://github.com/python/cpython.git
synced 2026-06-28 03:41:13 +00:00
Replace the previously sparse reference documentation with full coverage of
the public API of the tkinter package, written from the Tcl/Tk manual pages,
the existing documentation and the module docstrings.
* Doc/library/tkinter.rst gains a "Reference" section documenting every public
class, method, function and constant of the core module -- the widgets, the
Misc, Wm, Pack, Place, Grid, XView and YView mix-ins, the Variable and image
classes, the module-level functions and the symbolic constants.
* Doc/library/tkinter.ttk.rst, dialog.rst, tkinter.font.rst and the other
module pages document their remaining classes, methods and functions.
The descriptions are Python-oriented (correct return types -- tuples rather
than Tcl lists, booleans, integers, None on cancellation, and so on) and were
checked against the Tcl/Tk 9.1 manual pages and the implementation.
versionadded, versionchanged and deprecated directives are added for the
public API, determined from the git history relative to Python 3.0: the
tkinter.ttk module (3.1); the Text, Wm, Menu and Misc methods exposing Tk 8.5
features (3.3); and the many later additions and behavior changes up to 3.15.
The Tk version required by features added after Tk 8.6 is noted as well. The
bundled Tcl/Tk version is updated to 9.0 and the manual-page links point at
the tcl9.0 reference.
--------
(cherry picked from commit 8b270b72a2)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
200 lines
5.8 KiB
ReStructuredText
200 lines
5.8 KiB
ReStructuredText
:mod:`!tkinter.messagebox` --- Tkinter message prompts
|
|
======================================================
|
|
|
|
.. module:: tkinter.messagebox
|
|
:synopsis: Various types of alert dialogs
|
|
|
|
**Source code:** :source:`Lib/tkinter/messagebox.py`
|
|
|
|
--------------
|
|
|
|
The :mod:`!tkinter.messagebox` module provides a template base class as well as
|
|
a variety of convenience methods for commonly used configurations.
|
|
The message boxes are modal: each blocks until the user responds, then returns
|
|
a value that depends on the function.
|
|
The ``show*`` functions and :meth:`Message.show` return the symbolic name of
|
|
the button the user pressed, as a string (such as :data:`OK` or :data:`YES`),
|
|
while the ``ask*`` functions return a :class:`bool` or ``None`` (see each
|
|
function below).
|
|
Common message box styles and layouts include but are not limited to:
|
|
|
|
.. figure:: tk_msg.png
|
|
|
|
.. class:: Message(master=None, **options)
|
|
|
|
Create a message window with an application-specified message, an icon
|
|
and a set of buttons.
|
|
Each of the buttons in the message window is identified by a unique symbolic name (see the *type* options).
|
|
|
|
The following options are supported:
|
|
|
|
*command*
|
|
Specifies the function to invoke when the user closes the dialog.
|
|
The name of the button clicked by the user to close the dialog is
|
|
passed as argument.
|
|
This is only available on macOS.
|
|
|
|
*default*
|
|
Gives the :ref:`symbolic name <messagebox-buttons>` of the default button
|
|
for this message window (:data:`OK`, :data:`CANCEL`, and so on).
|
|
If this option is not specified, the first button in the dialog will
|
|
be made the default.
|
|
|
|
*detail*
|
|
Specifies an auxiliary message to the main message given by the
|
|
*message* option.
|
|
The message detail will be presented beneath the main message and,
|
|
where supported by the OS, in a less emphasized font than the main
|
|
message.
|
|
|
|
*icon*
|
|
Specifies an :ref:`icon <messagebox-icons>` to display.
|
|
If this option is not specified, then the :data:`INFO` icon will be
|
|
displayed.
|
|
|
|
*message*
|
|
Specifies the message to display in this message box.
|
|
The default value is an empty string.
|
|
|
|
*parent*
|
|
Makes the specified window the logical parent of the message box.
|
|
The message box is displayed on top of its parent window.
|
|
|
|
*title*
|
|
Specifies a string to display as the title of the message box.
|
|
This option is ignored on macOS, where platform guidelines forbid
|
|
the use of a title on this kind of dialog.
|
|
|
|
*type*
|
|
Arranges for a :ref:`predefined set of buttons <messagebox-types>`
|
|
to be displayed.
|
|
|
|
.. note::
|
|
|
|
Tk 8.6 added the *command* option.
|
|
|
|
.. method:: show(**options)
|
|
|
|
Display a message window and wait for the user to select one of the buttons. Then return the symbolic name of the selected button.
|
|
Keyword arguments can override options specified in the constructor.
|
|
|
|
|
|
**Information message box**
|
|
|
|
.. function:: showinfo(title=None, message=None, **options)
|
|
|
|
Creates and displays an information message box with the specified title
|
|
and message.
|
|
|
|
**Warning message boxes**
|
|
|
|
.. function:: showwarning(title=None, message=None, **options)
|
|
|
|
Creates and displays a warning message box with the specified title
|
|
and message.
|
|
|
|
.. function:: showerror(title=None, message=None, **options)
|
|
|
|
Creates and displays an error message box with the specified title
|
|
and message.
|
|
|
|
**Question message boxes**
|
|
|
|
.. function:: askquestion(title=None, message=None, *, type=YESNO, **options)
|
|
|
|
Ask a question. By default shows buttons :data:`YES` and :data:`NO`.
|
|
Returns the symbolic name of the selected button.
|
|
|
|
.. function:: askokcancel(title=None, message=None, **options)
|
|
|
|
Ask if operation should proceed. Shows buttons :data:`OK` and :data:`CANCEL`.
|
|
Returns ``True`` if the answer is ok and ``False`` otherwise.
|
|
|
|
.. function:: askretrycancel(title=None, message=None, **options)
|
|
|
|
Ask if operation should be retried. Shows buttons :data:`RETRY` and :data:`CANCEL`.
|
|
Return ``True`` if the answer is yes and ``False`` otherwise.
|
|
|
|
.. function:: askyesno(title=None, message=None, **options)
|
|
|
|
Ask a question. Shows buttons :data:`YES` and :data:`NO`.
|
|
Returns ``True`` if the answer is yes and ``False`` otherwise.
|
|
|
|
.. function:: askyesnocancel(title=None, message=None, **options)
|
|
|
|
Ask a question. Shows buttons :data:`YES`, :data:`NO` and :data:`CANCEL`.
|
|
Return ``True`` if the answer is yes, ``None`` if cancelled, and ``False``
|
|
otherwise.
|
|
|
|
|
|
.. _messagebox-buttons:
|
|
|
|
Symbolic names of buttons:
|
|
|
|
.. data:: ABORT
|
|
:value: 'abort'
|
|
.. data:: RETRY
|
|
:value: 'retry'
|
|
.. data:: IGNORE
|
|
:value: 'ignore'
|
|
.. data:: OK
|
|
:value: 'ok'
|
|
.. data:: CANCEL
|
|
:value: 'cancel'
|
|
.. data:: YES
|
|
:value: 'yes'
|
|
.. data:: NO
|
|
:value: 'no'
|
|
|
|
.. _messagebox-types:
|
|
|
|
Predefined sets of buttons:
|
|
|
|
.. data:: ABORTRETRYIGNORE
|
|
:value: 'abortretryignore'
|
|
|
|
Displays three buttons whose symbolic names are :data:`ABORT`,
|
|
:data:`RETRY` and :data:`IGNORE`.
|
|
|
|
.. data:: OK
|
|
:value: 'ok'
|
|
:noindex:
|
|
|
|
Displays one button whose symbolic name is :data:`OK`.
|
|
|
|
.. data:: OKCANCEL
|
|
:value: 'okcancel'
|
|
|
|
Displays two buttons whose symbolic names are :data:`OK` and
|
|
:data:`CANCEL`.
|
|
|
|
.. data:: RETRYCANCEL
|
|
:value: 'retrycancel'
|
|
|
|
Displays two buttons whose symbolic names are :data:`RETRY` and
|
|
:data:`CANCEL`.
|
|
|
|
.. data:: YESNO
|
|
:value: 'yesno'
|
|
|
|
Displays two buttons whose symbolic names are :data:`YES` and
|
|
:data:`NO`.
|
|
|
|
.. data:: YESNOCANCEL
|
|
:value: 'yesnocancel'
|
|
|
|
Displays three buttons whose symbolic names are :data:`YES`,
|
|
:data:`NO` and :data:`CANCEL`.
|
|
|
|
.. _messagebox-icons:
|
|
|
|
Icon images:
|
|
|
|
.. data:: ERROR
|
|
:value: 'error'
|
|
.. data:: INFO
|
|
:value: 'info'
|
|
.. data:: QUESTION
|
|
:value: 'question'
|
|
.. data:: WARNING
|
|
:value: 'warning'
|