Skip to content

Commit d4a953a

Browse files
[3.13] gh-86726: Document tkinter method-name conflicts (GH-151917) (GH-151934)
Document where widget methods shadow inherited Misc, geometry-manager and Wm methods, correct the inaccurate "size/bbox is an alias of grid_size/grid_bbox" claims, and add "# overrides X" comments at the definitions. Also document the geometry-manager ambiguity: the short names forget, info, slaves and propagate are defined by Pack, Place and Grid but resolve to the pack variant. Cross-reference the window-manager methods grid, forget and state with the same-named grid geometry manager, Pack.forget and ttk.Widget.state. (cherry picked from commit 4de5683) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 16c40f9 commit d4a953a

4 files changed

Lines changed: 159 additions & 31 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 121 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,11 +1266,19 @@ Base and mixin classes
12661266
If *belowThis* is given, the widget is moved to be just below it in the
12671267
stacking order instead.
12681268

1269+
:meth:`tkraise`/:meth:`lift` and :meth:`lower` are overridden by the
1270+
:class:`Canvas` widget,
1271+
where they restack canvas items instead.
1272+
12691273
.. method:: image_names()
12701274

12711275
Return the names of all images that currently exist in the Tcl
12721276
interpreter.
12731277

1278+
This is overridden by the :class:`Text` widget,
1279+
where :meth:`!image_names` returns the names of its embedded images
1280+
instead.
1281+
12741282
.. method:: image_types()
12751283

12761284
Return the available image types, such as ``'photo'`` and ``'bitmap'``.
@@ -1303,7 +1311,11 @@ Base and mixin classes
13031311
column 0 to that cell; if *col2* and *row2* are also given, it spans from
13041312
the cell (*column*, *row*) to the cell (*col2*, *row2*).
13051313

1306-
:meth:`bbox` is an alias of :meth:`!grid_bbox`.
1314+
:meth:`bbox` is an alias of :meth:`!grid_bbox`,
1315+
except on :class:`Canvas`, :class:`Listbox`, :class:`Spinbox`,
1316+
:class:`Text`, :class:`ttk.Entry <tkinter.ttk.Entry>` and
1317+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`,
1318+
which provide their own :meth:`!bbox` method.
13071319

13081320
.. method:: columnconfigure(index, cnf={}, **kw)
13091321
:no-typesetting:
@@ -1378,7 +1390,9 @@ Base and mixin classes
13781390
Return the size of the grid managed by this container as a
13791391
``(columns, rows)`` tuple.
13801392

1381-
:meth:`size` is an alias of :meth:`!grid_size`.
1393+
:meth:`size` is an alias of :meth:`!grid_size`,
1394+
except on the :class:`Listbox` widget,
1395+
which provides its own :meth:`!size` method.
13821396

13831397
.. method:: grid_slaves(row=None, column=None)
13841398

@@ -1647,7 +1661,10 @@ Base and mixin classes
16471661
widget's display, the widget is remembered as the focus window for its
16481662
top level, and the focus will be redirected to it the next time the
16491663
window manager gives the focus to the top level.
1650-
:meth:`focus` is an alias of :meth:`!focus_set`.
1664+
:meth:`focus` is an alias of :meth:`!focus_set`,
1665+
except on the :class:`Canvas` and
1666+
:class:`ttk.Treeview <tkinter.ttk.Treeview>` widgets,
1667+
which provide their own :meth:`!focus` method.
16511668

16521669
.. method:: focus_force()
16531670

@@ -1749,6 +1766,10 @@ Base and mixin classes
17491766
The *displayof* keyword argument names a widget that determines the
17501767
display on which to operate, and defaults to this widget.
17511768

1769+
This is overridden by the :class:`Entry`, :class:`Listbox` and
1770+
:class:`Spinbox` widgets,
1771+
where :meth:`!selection_clear` clears the widget's own selection instead.
1772+
17521773
.. method:: selection_get(**kw)
17531774

17541775
Return the contents of the current X selection.
@@ -1826,7 +1847,7 @@ Base and mixin classes
18261847
first and ``STRING`` is used as a fallback.
18271848
The *displayof* keyword argument names a widget that determines the
18281849
display, and defaults to the root window of the application.
1829-
This is equivalent to ``selection_get(selection= 'CLIPBOARD')``.
1850+
This is equivalent to ``selection_get(selection='CLIPBOARD')``.
18301851

18311852
.. method:: option_add(pattern, value, priority=None)
18321853

@@ -2512,6 +2533,8 @@ Base and mixin classes
25122533
widget is managed again.
25132534
:meth:`wm_forget` is an alias of :meth:`!forget`.
25142535

2536+
Not to be confused with :meth:`Pack.forget`.
2537+
25152538
.. versionadded:: 3.3
25162539

25172540
.. method:: wm_frame()
@@ -2557,6 +2580,8 @@ Base and mixin classes
25572580
string if the window is not gridded.
25582581
:meth:`wm_grid` is an alias of :meth:`!grid`.
25592582

2583+
Not to be confused with the grid geometry manager :meth:`Grid.grid`.
2584+
25602585
.. method:: wm_group(pathName=None)
25612586
:no-typesetting:
25622587

@@ -2794,6 +2819,9 @@ Base and mixin classes
27942819
:meth:`iconwindow`); the ``'icon'`` state cannot be set.
27952820
:meth:`wm_state` is an alias of :meth:`!state`.
27962821

2822+
Not to be confused with :meth:`ttk.Widget.state
2823+
<tkinter.ttk.Widget.state>`.
2824+
27972825
.. method:: wm_title(string=None)
27982826
:no-typesetting:
27992827

@@ -2845,6 +2873,21 @@ Base and mixin classes
28452873
*pack* geometry manager.
28462874
See also :ref:`pack-the-packer`.
28472875

2876+
.. note::
2877+
2878+
:class:`Pack`, :class:`Place` and :class:`Grid` all define the short
2879+
method names :meth:`!forget`, :meth:`!info`, :meth:`!slaves`,
2880+
:meth:`!content` and :meth:`!propagate`.
2881+
On a widget the bare names resolve to the *pack* manager's versions,
2882+
since :class:`Pack` and :class:`Misc` precede :class:`Place` and
2883+
:class:`Grid` in the method resolution order,
2884+
whatever manager actually manages the widget;
2885+
and :meth:`!configure`/:meth:`!config` configure the widget's options,
2886+
not its geometry.
2887+
Use the explicit ``pack_*``, ``grid_*`` and ``place_*`` methods
2888+
(and ``pack``, ``grid``, ``place`` for geometry configuration)
2889+
to act on a specific geometry manager.
2890+
28482891
.. method:: configure(cnf={}, **kw)
28492892
:no-typesetting:
28502893

@@ -2907,7 +2950,13 @@ Base and mixin classes
29072950
Unmap the widget and remove it from the packing order, forgetting its
29082951
packing options.
29092952
It can be packed again later with :meth:`pack_configure`.
2910-
:meth:`forget` is an alias of :meth:`!pack_forget`.
2953+
:meth:`forget` is an alias of :meth:`!pack_forget`,
2954+
except on :class:`PanedWindow`,
2955+
:class:`ttk.Notebook <tkinter.ttk.Notebook>` and
2956+
:class:`ttk.PanedWindow <tkinter.ttk.PanedWindow>`,
2957+
which provide their own :meth:`!forget` method.
2958+
2959+
Not to be confused with :meth:`Wm.forget`.
29112960

29122961
.. method:: info()
29132962
:no-typesetting:
@@ -3004,15 +3053,13 @@ Base and mixin classes
30043053

30053054
Unmap the widget and remove it from the placement, forgetting its place
30063055
options.
3007-
:meth:`forget` is an alias of :meth:`!place_forget`.
30083056

30093057
.. method:: info()
30103058
:no-typesetting:
30113059

30123060
.. method:: place_info()
30133061

30143062
Return a dictionary of the widget's current place options.
3015-
:meth:`info` is an alias of :meth:`!place_info`.
30163063

30173064
.. method:: slaves()
30183065
:no-typesetting:
@@ -3021,7 +3068,6 @@ Base and mixin classes
30213068

30223069
Same as :meth:`Misc.place_slaves`: return the list of widgets placed in
30233070
this widget.
3024-
:meth:`slaves` is an alias of :meth:`!place_slaves`.
30253071

30263072

30273073
.. class:: Grid()
@@ -3041,6 +3087,9 @@ Base and mixin classes
30413087
grid(cnf={}, **kw)
30423088
30433089
Position the widget in a cell of its container's grid.
3090+
3091+
Not to be confused with :meth:`Wm.grid`.
3092+
30443093
The supported options are:
30453094

30463095
*row*, *column*
@@ -3085,7 +3134,6 @@ Base and mixin classes
30853134

30863135
Unmap the widget and remove it from the grid, forgetting its grid
30873136
options.
3088-
:meth:`forget` is an alias of :meth:`!grid_forget`.
30893137

30903138
.. method:: grid_remove()
30913139

@@ -3098,15 +3146,18 @@ Base and mixin classes
30983146
.. method:: grid_info()
30993147

31003148
Return a dictionary of the widget's current grid options.
3101-
:meth:`info` is an alias of :meth:`!grid_info`.
31023149

31033150
.. method:: bbox(column=None, row=None, col2=None, row2=None)
31043151
:no-typesetting:
31053152

31063153
.. method:: grid_bbox(column=None, row=None, col2=None, row2=None)
31073154

31083155
Same as :meth:`Misc.grid_bbox`.
3109-
:meth:`bbox` is an alias of :meth:`!grid_bbox`.
3156+
:meth:`bbox` is an alias of :meth:`!grid_bbox`,
3157+
except on :class:`Canvas`, :class:`Listbox`, :class:`Spinbox`,
3158+
:class:`Text`, :class:`ttk.Entry <tkinter.ttk.Entry>` and
3159+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`,
3160+
which provide their own :meth:`!bbox` method.
31103161

31113162
.. method:: columnconfigure(index, cnf={}, **kw)
31123163
:no-typesetting:
@@ -3142,7 +3193,9 @@ Base and mixin classes
31423193

31433194
Same as :meth:`Misc.grid_size`: return a ``(columns, rows)`` tuple giving
31443195
the size of the grid.
3145-
:meth:`size` is an alias of :meth:`!grid_size`.
3196+
:meth:`size` is an alias of :meth:`!grid_size`,
3197+
except on the :class:`Listbox` widget,
3198+
which provides its own :meth:`!size` method.
31463199

31473200
.. method:: propagate()
31483201
propagate(flag)
@@ -3152,7 +3205,6 @@ Base and mixin classes
31523205
grid_propagate(flag)
31533206

31543207
Same as :meth:`Misc.grid_propagate`.
3155-
:meth:`propagate` is an alias of :meth:`!grid_propagate`.
31563208

31573209
.. method:: slaves(row=None, column=None)
31583210
:no-typesetting:
@@ -3161,7 +3213,6 @@ Base and mixin classes
31613213

31623214
Same as :meth:`Misc.grid_slaves`: return the widgets managed in the grid,
31633215
optionally restricted to a *row* and/or *column*.
3164-
:meth:`slaves` is an alias of :meth:`!grid_slaves`.
31653216

31663217

31673218
.. class:: XView()
@@ -3761,6 +3812,14 @@ Widget classes
37613812
This has no effect on embedded window items.
37623813
:meth:`lower` is an alias of :meth:`!tag_lower`.
37633814

3815+
.. note::
3816+
3817+
On a :class:`Canvas`, :meth:`tkraise`/:meth:`lift` and :meth:`lower`
3818+
restack canvas items,
3819+
shadowing the inherited :meth:`Misc.tkraise`/:meth:`Misc.lift` and
3820+
:meth:`Misc.lower` methods that restack the widget itself,
3821+
which are therefore not available.
3822+
37643823
.. method:: tag_bind(tagOrId, sequence=None, func=None, add=None)
37653824

37663825
Bind the callback *func* to the event *sequence* for all items given by
@@ -3796,6 +3855,9 @@ Widget classes
37963855
Return ``None`` if no item matches or the matching items have nothing to
37973856
display.
37983857

3858+
This shadows the inherited :meth:`!Misc.bbox`;
3859+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
3860+
37993861
.. method:: canvasx(screenx, gridspacing=None)
38003862

38013863
Given a window x-coordinate *screenx*, return the canvas x-coordinate
@@ -3822,6 +3884,9 @@ Widget classes
38223884
An item only displays the insertion cursor when both it is the focus item
38233885
and its canvas has the input focus.
38243886

3887+
This shadows the inherited :meth:`!Misc.focus`;
3888+
use :meth:`~Misc.focus_set` to focus the widget itself.
3889+
38253890
.. method:: icursor(tagOrId, index, /)
38263891

38273892
Set the insertion cursor of the items given by *tagOrId* to just before
@@ -4019,6 +4084,12 @@ Widget classes
40194084
If the selection is not in this widget the method has no effect.
40204085
:meth:`select_clear` is an alias of :meth:`!selection_clear`.
40214086

4087+
.. note::
4088+
4089+
This shadows the inherited :meth:`Misc.selection_clear`,
4090+
which clears the X selection;
4091+
that method is not available on an :class:`Entry`.
4092+
40224093
.. method:: select_from(index)
40234094
:no-typesetting:
40244095

@@ -4158,6 +4229,9 @@ Widget classes
41584229

41594230
Return the total number of items in the listbox.
41604231

4232+
This shadows the inherited :meth:`!Misc.size`;
4233+
use :meth:`~Misc.grid_size` for the grid size.
4234+
41614235
.. method:: index(index)
41624236

41634237
Return the integer index value corresponding to *index*, or ``None`` if
@@ -4174,6 +4248,9 @@ Widget classes
41744248
visible, the result still gives the full area of the item, including the
41754249
parts that are not visible.
41764250

4251+
This shadows the inherited :meth:`!Misc.bbox`;
4252+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
4253+
41774254
.. method:: nearest(y)
41784255

41794256
Given a y-coordinate within the listbox window, return the index of the
@@ -4222,6 +4299,12 @@ Widget classes
42224299
The selection state of items outside this range is not changed.
42234300
:meth:`select_clear` is an alias of :meth:`!selection_clear`.
42244301

4302+
.. note::
4303+
4304+
This shadows the inherited :meth:`Misc.selection_clear`,
4305+
which clears the X selection;
4306+
that method is not available on a :class:`Listbox`.
4307+
42254308
.. method:: select_includes(index)
42264309
:no-typesetting:
42274310

@@ -4603,6 +4686,9 @@ Widget classes
46034686
Remove the pane containing *child* from the panedwindow.
46044687
All geometry management options for *child* are forgotten.
46054688
:meth:`forget` is an alias of :meth:`!remove`.
4689+
This shadows the inherited geometry-manager :meth:`!forget`;
4690+
use :meth:`~Pack.pack_forget`, :meth:`~Grid.grid_forget` or
4691+
:meth:`~Place.place_forget` to remove the widget itself from its manager.
46064692

46074693
.. method:: panes()
46084694

@@ -4894,6 +4980,9 @@ Widget classes
48944980
The bounding box may refer to a region outside the visible area of the
48954981
window.
48964982

4983+
This shadows the inherited :meth:`!Misc.bbox`;
4984+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
4985+
48974986
.. method:: identify(x, y)
48984987

48994988
Return the name of the window element at the pixel coordinates *x*, *y*:
@@ -4955,6 +5044,12 @@ Widget classes
49555044
Clear the selection if it is currently in this widget.
49565045
If the selection is not in this widget, the method has no effect.
49575046

5047+
.. note::
5048+
5049+
This shadows the inherited :meth:`Misc.selection_clear`,
5050+
which clears the X selection;
5051+
that method is not available on a :class:`Spinbox`.
5052+
49585053
.. method:: selection_element(element=None)
49595054

49605055
Set or get the currently selected element.
@@ -5112,6 +5207,9 @@ Widget classes
51125207
pixels, of the visible part of the character at *index*, or ``None`` if
51135208
that character is not visible on the screen.
51145209

5210+
This shadows the inherited :meth:`!Misc.bbox`;
5211+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
5212+
51155213
.. method:: dlineinfo(index)
51165214

51175215
Return a tuple ``(x, y, width, height, baseline)`` describing the display
@@ -5366,6 +5464,12 @@ Widget classes
53665464

53675465
Return a tuple of the names of all images embedded in the widget.
53685466

5467+
.. note::
5468+
5469+
This shadows the inherited :meth:`Misc.image_names`,
5470+
which returns the names of all images in the Tcl interpreter;
5471+
that method is not available on a :class:`Text`.
5472+
53695473
.. method:: window_create(index, cnf={}, **kw)
53705474

53715475
Embed a window (any widget) at *index*.
@@ -5556,6 +5660,7 @@ Variable classes
55565660
.. method:: set(value)
55575661

55585662
Set the variable to *value*.
5663+
:meth:`initialize` is an alias of :meth:`!set`.
55595664

55605665
.. versionadded:: 3.3
55615666
The *initialize* spelling.
@@ -5602,6 +5707,7 @@ Variable classes
56025707
*mode* is one of the strings ``'r'``, ``'w'`` or ``'u'``, for read, write
56035708
or unset.
56045709
Return the internal name of the registered callback.
5710+
:meth:`trace` is an alias of :meth:`!trace_variable`.
56055711

56065712
.. deprecated:: 3.6
56075713
Use :meth:`trace_add` instead. This method wraps a Tcl feature that
@@ -5673,6 +5779,7 @@ Variable classes
56735779
.. method:: set(value)
56745780

56755781
Set the variable to *value*, converting it to a boolean.
5782+
:meth:`initialize` is an alias of :meth:`!set`.
56765783

56775784
.. versionadded:: 3.3
56785785
The *initialize* spelling.

0 commit comments

Comments
 (0)