Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions Doc/library/dialog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The :mod:`!tkinter.simpledialog` module contains convenience classes and
functions for creating simple modal dialogs to get a value from the user.


.. function:: askfloat(title, prompt, *, initialvalue=None, minvalue=None, maxvalue=None, parent=None)
askinteger(title, prompt, *, initialvalue=None, minvalue=None, maxvalue=None, parent=None)
askstring(title, prompt, *, initialvalue=None, show=None, parent=None)
.. function:: askfloat(title, prompt, *, initialvalue=None, minvalue=None, maxvalue=None, parent=None, use_ttk=True)
askinteger(title, prompt, *, initialvalue=None, minvalue=None, maxvalue=None, parent=None, use_ttk=True)
askstring(title, prompt, *, initialvalue=None, show=None, parent=None, use_ttk=True)

Prompt the user to enter a value of the desired type and return it, or
``None`` if the dialog is cancelled.
Expand All @@ -29,12 +29,22 @@ functions for creating simple modal dialogs to get a value from the user.
*maxvalue*, which bound the accepted value.
:func:`askstring` also accepts *show*, a character used to mask the entered
text, for example ``'*'`` to hide a password.
They use the themed :mod:`tkinter.ttk` widgets; pass ``use_ttk=False`` for
the classic widgets.

.. class:: Dialog(parent, title=None)
.. class:: Dialog(parent, title=None, *, use_ttk=False)

The base class for custom dialogs.
Instantiating it shows the dialog modally and returns once the user closes
it; the entered value is then available in the :attr:`!result` attribute.
When *use_ttk* is false (the default), the dialog is built from the classic
:mod:`tkinter` widgets, modelled on the classic ``tk_dialog``; when true,
from the themed :mod:`tkinter.ttk` widgets, modelled on the Tk message box.
The default is classic for compatibility, since the themed widgets set a
themed background that classic widgets added in :meth:`body` would not match.

.. versionchanged:: next
Added the *use_ttk* parameter.

.. attribute:: result

Expand Down Expand Up @@ -74,14 +84,32 @@ functions for creating simple modal dialogs to get a value from the user.
the initial focus.


.. class:: SimpleDialog(master, text='', buttons=[], default=None, cancel=None, title=None, class_=None)
.. class:: SimpleDialog(master, text='', buttons=[], default=None, cancel=None, title=None, class_=None, *, bitmap=None, detail='', use_ttk=True)

A simple modal dialog that displays the message *text* above a row of push
buttons whose labels are given by *buttons*, and returns the index of the
button the user presses.
*default* is the index of the button activated by the Return key, *cancel*
the index returned when the window is closed through the window manager,
*title* the window title, and *class_* the Tk class name of the window.
buttons given by *buttons*, and returns the index of the button the user
presses.
Each entry of *buttons* is either a button label, or a mapping of button
options such as ``{'text': 'OK', 'underline': 0}``; an ``underline`` option
makes :kbd:`Alt` plus the underlined character invoke the button.
*default* is the index of the default button, activated by the Return key
when no button has the focus, *cancel* the index returned when the window is
closed through the window manager, *title* the window title, and *class_*
the Tk class name of the window.
*bitmap* is the name of a bitmap displayed beside the message
(for example ``'warning'`` or ``'question'``); the standard names
``'error'``, ``'info'``, ``'question'`` and ``'warning'`` are shown as
themed icons when *use_ttk* is true.
*detail* is a secondary message displayed below *text*.
When *use_ttk* is true (the default), the dialog is built from the themed
:mod:`tkinter.ttk` widgets, modelled on the Tk message box; when false, from
the classic :mod:`tkinter` widgets, modelled on ``tk_dialog``.

.. versionchanged:: next
The dialog is now built from the themed :mod:`tkinter.ttk` widgets by
default, instead of the classic :mod:`tkinter` widgets.
Added the *bitmap*, *detail* and *use_ttk* parameters.
Entries of *buttons* may be mappings of button options.

.. method:: go()

Expand Down
16 changes: 16 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ tkinter
options as keyword arguments, which can also override its default appearance.
(Contributed by Serhiy Storchaka in :gh:`101284`.)

* The :mod:`tkinter.simpledialog` dialogs were modernized to match the look
and feel of the native Tk dialogs.
:class:`!tkinter.simpledialog.SimpleDialog` and the
:func:`~tkinter.simpledialog.askinteger`,
:func:`~tkinter.simpledialog.askfloat` and
:func:`~tkinter.simpledialog.askstring` dialogs are now built from the themed
:mod:`tkinter.ttk` widgets instead of the classic :mod:`tkinter` widgets;
the :class:`!tkinter.simpledialog.Dialog` base class still defaults to the
classic widgets for compatibility. Both :class:`!Dialog` and
:class:`!SimpleDialog` gained a *use_ttk* parameter that selects between the
classic Tk widgets and the themed ttk widgets. :class:`!SimpleDialog` also
gained *bitmap* and
*detail* parameters, draws the standard icons with themed images in the
ttk version, and accepts mappings of button options as *buttons* entries.
(Contributed by Serhiy Storchaka in :gh:`59396`.)

xml
---

Expand Down
Loading
Loading