Skip to content

Commit 4e5aa2a

Browse files
serhiy-storchakaclaude
authored andcommitted
gh-86726: Fix and improve tkinter documentation and docstrings (GH-153549)
Correct inaccurate return-type and option descriptions in the tkinter reference, and add missing module and class docstrings. (cherry picked from commit 77cb756) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 96bd750 commit 4e5aa2a

11 files changed

Lines changed: 49 additions & 31 deletions

File tree

Doc/library/dialog.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,16 @@ specific value.
175175

176176
.. class:: Open(master=None, **options)
177177
SaveAs(master=None, **options)
178+
Directory(master=None, **options)
178179
179-
The above two classes provide native dialog windows for saving and loading
180-
files.
180+
The above three classes provide native dialog windows for loading and saving
181+
files and for selecting a directory.
181182

182183
**Convenience classes**
183184

184185
The below classes are used for creating file/directory windows from scratch.
185186
These do not emulate the native look-and-feel of the platform.
186187

187-
.. class:: Directory(master=None, **options)
188-
189-
Create a dialog prompting the user to select a directory.
190-
191188
.. note:: The *FileDialog* class should be subclassed for custom event
192189
handling and behaviour.
193190

@@ -311,23 +308,25 @@ the classic (non-themed) Tk widgets.
311308

312309
.. data:: DIALOG_ICON
313310

314-
The name of the default bitmap (``'questhead'``) displayed by a
315-
:class:`Dialog`.
311+
The name of a bitmap (``'questhead'``) suitable for use as the *bitmap*
312+
of a :class:`Dialog`.
316313

317314
.. class:: Dialog(master=None, cnf={}, **kw)
318315

319316
Display a modal dialog box built from the classic (non-themed) Tk widgets
320317
and wait for the user to press one of its buttons.
321-
The options, given through *cnf* or as keyword arguments, include *title*
322-
(the window title), *text* (the message), *bitmap* (an icon,
323-
:data:`DIALOG_ICON` by default), *default* (the index of the default button)
324-
and *strings* (the sequence of button labels).
318+
The options, given through *cnf* or as keyword arguments, are all required:
319+
*title* (the window title), *text* (the message), *bitmap* (the name of a
320+
bitmap icon, such as :data:`DIALOG_ICON`), *default* (the index of the
321+
default button) and *strings* (the sequence of button labels).
325322
After construction, the :attr:`!num` attribute holds the index of the button
326323
the user pressed.
327324

328325
.. method:: destroy()
329326

330-
Destroy the dialog window.
327+
Do nothing.
328+
The dialog window is destroyed automatically before the constructor
329+
returns, so there is nothing left for this method to do.
331330

332331

333332
.. seealso::

Doc/library/tkinter.messagebox.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ a variety of convenience methods for commonly used configurations.
1313
The message boxes are modal: each blocks until the user responds, then returns
1414
a value that depends on the function.
1515
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-
while the ``ask*`` functions return a :class:`bool` or ``None`` (see each
18-
function below).
16+
the button the user pressed, as a string (such as :data:`OK` or :data:`YES`).
1917
Common message box styles and layouts include but are not limited to:
2018

2119
.. figure:: tk_msg.png

Doc/library/tkinter.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,8 +2251,8 @@ Base and mixin classes
22512251
If all four arguments are given, the window manager keeps the ratio
22522252
between ``minNumer/minDenom`` and ``maxNumer/maxDenom``; passing empty
22532253
strings removes any existing restriction.
2254-
With no arguments, return a tuple of the four current values, or an empty
2255-
string if no aspect restriction is in effect.
2254+
With no arguments, return a tuple of the four current values, or ``None``
2255+
if no aspect restriction is in effect.
22562256
:meth:`wm_aspect` is an alias of :meth:`!aspect`.
22572257

22582258
.. method:: wm_attributes(*args, return_python_dict=False, **kwargs)
@@ -2477,8 +2477,8 @@ Base and mixin classes
24772477
window's internally requested size, and *widthInc* and *heightInc* are
24782478
the pixel sizes of a horizontal and vertical grid unit.
24792479
Empty strings turn off gridded management.
2480-
With no arguments, return a tuple of the four current values, or an empty
2481-
string if the window is not gridded.
2480+
With no arguments, return a tuple of the four current values, or ``None``
2481+
if the window is not gridded.
24822482
:meth:`wm_grid` is an alias of :meth:`!grid`.
24832483

24842484
Not to be confused with the grid geometry manager :meth:`Grid.grid`.
@@ -2573,8 +2573,8 @@ Base and mixin classes
25732573
Set or query a hint to the window manager about where the window's icon
25742574
should be positioned.
25752575
Empty strings cancel an existing hint.
2576-
With no arguments, return a tuple of the two current values, or an empty
2577-
string if no hint is in effect.
2576+
With no arguments, return a tuple of the two current values, or ``None``
2577+
if no hint is in effect.
25782578
:meth:`wm_iconposition` is an alias of :meth:`!iconposition`.
25792579

25802580
.. method:: wm_iconwindow(pathName=None)
@@ -2643,7 +2643,8 @@ Base and mixin classes
26432643
When this flag is set, the window is ignored by the window manager: it is
26442644
not reparented into a decorative frame and the user cannot manipulate it
26452645
through the usual window manager controls.
2646-
With no argument, return a boolean indicating whether the flag is set.
2646+
With no argument, return a boolean indicating whether the flag is set,
2647+
or ``None`` if it has not been set.
26472648
The flag is reliably honored only when the window is first mapped or
26482649
remapped from the withdrawn state.
26492650
:meth:`wm_overrideredirect` is an alias of :meth:`!overrideredirect`.

Doc/library/tkinter.ttk.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ To override the basic Tk widgets, the import should follow the Tk import::
4444

4545
That code causes several :mod:`!tkinter.ttk` widgets (:class:`Button`,
4646
:class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :class:`Label`,
47-
:class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`,
48-
:class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`) to
47+
:class:`LabelFrame`, :class:`Menubutton`, :class:`OptionMenu`,
48+
:class:`PanedWindow`, :class:`Radiobutton`, :class:`Scale`,
49+
:class:`Scrollbar` and :class:`Spinbox`) to
4950
automatically replace the Tk widgets.
5051

5152
This has the direct benefit of using the new widgets which gives a better look
@@ -1041,6 +1042,9 @@ ttk.Treeview
10411042
The minimum width of the column in pixels. The treeview widget will
10421043
not make the column any smaller than specified by this option when
10431044
the widget is resized or the user drags a column.
1045+
*separator*: ``True``/``False``
1046+
Specifies whether a column separator should be drawn to the right of
1047+
the column.
10441048
*stretch*: ``True``/``False``
10451049
Specifies whether the column's width should be adjusted when
10461050
the widget is resized.
@@ -1754,8 +1758,11 @@ and inherits the common methods of :class:`Widget`.
17541758
display in the menu.
17551759
A *command* keyword argument may be given to specify a callable that is
17561760
invoked with the selected value whenever the selection changes; the *style*
1757-
keyword argument sets the style used by the underlying menubutton; and the
1758-
*name* keyword argument sets the Tk widget name.
1761+
keyword argument sets the style used by the underlying menubutton; the
1762+
*direction* keyword argument sets where the menu is posted relative to the
1763+
menubutton (one of ``'above'``, ``'below'`` (the default), ``'left'``,
1764+
``'right'`` or ``'flush'``); and the *name* keyword argument sets the Tk
1765+
widget name.
17591766

17601767
.. method:: set_menu(default=None, *values)
17611768

Lib/tkinter/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Tkinter provides classes which allow the display, positioning and
44
control of widgets. Toplevel widgets are Tk and Toplevel. Other
55
widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
6-
Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
6+
Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox,
77
LabelFrame and PanedWindow.
88
99
Properties of the widgets are specified with keyword arguments.
@@ -2365,7 +2365,7 @@ def wm_iconphoto(self, default=False, *args): # new in Tk 8.5
23652365

23662366
def wm_iconposition(self, x=None, y=None):
23672367
"""Set the position of the icon of this widget to X and Y. Return
2368-
a tuple of the current values of X and X if None is given."""
2368+
a tuple of the current values of X and Y if None is given."""
23692369
return self._getints(self.tk.call(
23702370
'wm', 'iconposition', self._w, x, y))
23712371

Lib/tkinter/colorchooser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Interface to the native Tk color selection dialog."""
2+
13
# tk common color chooser dialogue
24
#
35
# this module provides an interface to the native color dialogue

Lib/tkinter/commondialog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Base class for the Tk common dialogs."""
2+
13
# base class for tk common dialogues
24
#
35
# this module provides a base class for accessing the common

Lib/tkinter/dialog.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# dialog.py -- Tkinter interface to the tk_dialog script.
22

3+
"""Classic Tk dialog box, wrapping the tk_dialog script."""
4+
35
from tkinter import _cnfmerge, Widget, TclError, Button, Pack
46

57
__all__ = ["Dialog"]
@@ -8,6 +10,8 @@
810

911

1012
class Dialog(Widget):
13+
"""A modal dialog box built from the classic (non-themed) Tk widgets."""
14+
1115
def __init__(self, master=None, cnf={}, **kw):
1216
cnf = _cnfmerge((cnf, kw))
1317
self.widgetName = '__dialog__'
@@ -21,7 +25,8 @@ def __init__(self, master=None, cnf={}, **kw):
2125
try: Widget.destroy(self)
2226
except TclError: pass
2327

24-
def destroy(self): pass
28+
def destroy(self):
29+
"""Do nothing; the dialog window is already destroyed."""
2530

2631

2732
def _test():

Lib/tkinter/font.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Utilities to help work with fonts in Tkinter."""
2+
13
# Tkinter font wrapper
24
#
35
# written by Fredrik Lundh, February 1998

Lib/tkinter/messagebox.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Interface to the standard Tk message boxes."""
2+
13
# tk common message boxes
24
#
35
# this module provides an interface to the native message boxes

0 commit comments

Comments
 (0)