Skip to content

Commit ecd22d4

Browse files
[3.14] gh-86726: Document tkinter method-name conflicts (GH-151917)
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, content 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: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b93d6d3 commit ecd22d4

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
@@ -1268,11 +1268,19 @@ Base and mixin classes
12681268
If *belowThis* is given, the widget is moved to be just below it in the
12691269
stacking order instead.
12701270

1271+
:meth:`tkraise`/:meth:`lift` and :meth:`lower` are overridden by the
1272+
:class:`Canvas` widget,
1273+
where they restack canvas items instead.
1274+
12711275
.. method:: image_names()
12721276

12731277
Return the names of all images that currently exist in the Tcl
12741278
interpreter.
12751279

1280+
This is overridden by the :class:`Text` widget,
1281+
where :meth:`!image_names` returns the names of its embedded images
1282+
instead.
1283+
12761284
.. method:: image_types()
12771285

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

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

13101322
.. method:: columnconfigure(index, cnf={}, **kw)
13111323
:no-typesetting:
@@ -1380,7 +1392,9 @@ Base and mixin classes
13801392
Return the size of the grid managed by this container as a
13811393
``(columns, rows)`` tuple.
13821394

1383-
:meth:`size` is an alias of :meth:`!grid_size`.
1395+
:meth:`size` is an alias of :meth:`!grid_size`,
1396+
except on the :class:`Listbox` widget,
1397+
which provides its own :meth:`!size` method.
13841398

13851399
.. method:: grid_slaves(row=None, column=None)
13861400

@@ -1655,7 +1669,10 @@ Base and mixin classes
16551669
widget's display, the widget is remembered as the focus window for its
16561670
top level, and the focus will be redirected to it the next time the
16571671
window manager gives the focus to the top level.
1658-
:meth:`focus` is an alias of :meth:`!focus_set`.
1672+
:meth:`focus` is an alias of :meth:`!focus_set`,
1673+
except on the :class:`Canvas` and
1674+
:class:`ttk.Treeview <tkinter.ttk.Treeview>` widgets,
1675+
which provide their own :meth:`!focus` method.
16591676

16601677
.. method:: focus_force()
16611678

@@ -1757,6 +1774,10 @@ Base and mixin classes
17571774
The *displayof* keyword argument names a widget that determines the
17581775
display on which to operate, and defaults to this widget.
17591776

1777+
This is overridden by the :class:`Entry`, :class:`Listbox` and
1778+
:class:`Spinbox` widgets,
1779+
where :meth:`!selection_clear` clears the widget's own selection instead.
1780+
17601781
.. method:: selection_get(**kw)
17611782

17621783
Return the contents of the current X selection.
@@ -1834,7 +1855,7 @@ Base and mixin classes
18341855
first and ``STRING`` is used as a fallback.
18351856
The *displayof* keyword argument names a widget that determines the
18361857
display, and defaults to the root window of the application.
1837-
This is equivalent to ``selection_get(selection= 'CLIPBOARD')``.
1858+
This is equivalent to ``selection_get(selection='CLIPBOARD')``.
18381859

18391860
.. method:: option_add(pattern, value, priority=None)
18401861

@@ -2520,6 +2541,8 @@ Base and mixin classes
25202541
widget is managed again.
25212542
:meth:`wm_forget` is an alias of :meth:`!forget`.
25222543

2544+
Not to be confused with :meth:`Pack.forget`.
2545+
25232546
.. versionadded:: 3.3
25242547

25252548
.. method:: wm_frame()
@@ -2565,6 +2588,8 @@ Base and mixin classes
25652588
string if the window is not gridded.
25662589
:meth:`wm_grid` is an alias of :meth:`!grid`.
25672590

2591+
Not to be confused with the grid geometry manager :meth:`Grid.grid`.
2592+
25682593
.. method:: wm_group(pathName=None)
25692594
:no-typesetting:
25702595

@@ -2802,6 +2827,9 @@ Base and mixin classes
28022827
:meth:`iconwindow`); the ``'icon'`` state cannot be set.
28032828
:meth:`wm_state` is an alias of :meth:`!state`.
28042829

2830+
Not to be confused with :meth:`ttk.Widget.state
2831+
<tkinter.ttk.Widget.state>`.
2832+
28052833
.. method:: wm_title(string=None)
28062834
:no-typesetting:
28072835

@@ -2853,6 +2881,21 @@ Base and mixin classes
28532881
*pack* geometry manager.
28542882
See also :ref:`pack-the-packer`.
28552883

2884+
.. note::
2885+
2886+
:class:`Pack`, :class:`Place` and :class:`Grid` all define the short
2887+
method names :meth:`!forget`, :meth:`!info`, :meth:`!slaves`,
2888+
:meth:`!content` and :meth:`!propagate`.
2889+
On a widget the bare names resolve to the *pack* manager's versions,
2890+
since :class:`Pack` and :class:`Misc` precede :class:`Place` and
2891+
:class:`Grid` in the method resolution order,
2892+
whatever manager actually manages the widget;
2893+
and :meth:`!configure`/:meth:`!config` configure the widget's options,
2894+
not its geometry.
2895+
Use the explicit ``pack_*``, ``grid_*`` and ``place_*`` methods
2896+
(and ``pack``, ``grid``, ``place`` for geometry configuration)
2897+
to act on a specific geometry manager.
2898+
28562899
.. method:: configure(cnf={}, **kw)
28572900
:no-typesetting:
28582901

@@ -2915,7 +2958,13 @@ Base and mixin classes
29152958
Unmap the widget and remove it from the packing order, forgetting its
29162959
packing options.
29172960
It can be packed again later with :meth:`pack_configure`.
2918-
:meth:`forget` is an alias of :meth:`!pack_forget`.
2961+
:meth:`forget` is an alias of :meth:`!pack_forget`,
2962+
except on :class:`PanedWindow`,
2963+
:class:`ttk.Notebook <tkinter.ttk.Notebook>` and
2964+
:class:`ttk.PanedWindow <tkinter.ttk.PanedWindow>`,
2965+
which provide their own :meth:`!forget` method.
2966+
2967+
Not to be confused with :meth:`Wm.forget`.
29192968

29202969
.. method:: info()
29212970
:no-typesetting:
@@ -3012,15 +3061,13 @@ Base and mixin classes
30123061

30133062
Unmap the widget and remove it from the placement, forgetting its place
30143063
options.
3015-
:meth:`forget` is an alias of :meth:`!place_forget`.
30163064

30173065
.. method:: info()
30183066
:no-typesetting:
30193067

30203068
.. method:: place_info()
30213069

30223070
Return a dictionary of the widget's current place options.
3023-
:meth:`info` is an alias of :meth:`!place_info`.
30243071

30253072
.. method:: slaves()
30263073
:no-typesetting:
@@ -3029,7 +3076,6 @@ Base and mixin classes
30293076

30303077
Same as :meth:`Misc.place_slaves`: return the list of widgets placed in
30313078
this widget.
3032-
:meth:`slaves` is an alias of :meth:`!place_slaves`.
30333079

30343080

30353081
.. class:: Grid()
@@ -3049,6 +3095,9 @@ Base and mixin classes
30493095
grid(cnf={}, **kw)
30503096
30513097
Position the widget in a cell of its container's grid.
3098+
3099+
Not to be confused with :meth:`Wm.grid`.
3100+
30523101
The supported options are:
30533102

30543103
*row*, *column*
@@ -3093,7 +3142,6 @@ Base and mixin classes
30933142

30943143
Unmap the widget and remove it from the grid, forgetting its grid
30953144
options.
3096-
:meth:`forget` is an alias of :meth:`!grid_forget`.
30973145

30983146
.. method:: grid_remove()
30993147

@@ -3106,15 +3154,18 @@ Base and mixin classes
31063154
.. method:: grid_info()
31073155

31083156
Return a dictionary of the widget's current grid options.
3109-
:meth:`info` is an alias of :meth:`!grid_info`.
31103157

31113158
.. method:: bbox(column=None, row=None, col2=None, row2=None)
31123159
:no-typesetting:
31133160

31143161
.. method:: grid_bbox(column=None, row=None, col2=None, row2=None)
31153162

31163163
Same as :meth:`Misc.grid_bbox`.
3117-
:meth:`bbox` is an alias of :meth:`!grid_bbox`.
3164+
:meth:`bbox` is an alias of :meth:`!grid_bbox`,
3165+
except on :class:`Canvas`, :class:`Listbox`, :class:`Spinbox`,
3166+
:class:`Text`, :class:`ttk.Entry <tkinter.ttk.Entry>` and
3167+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`,
3168+
which provide their own :meth:`!bbox` method.
31183169

31193170
.. method:: columnconfigure(index, cnf={}, **kw)
31203171
:no-typesetting:
@@ -3150,7 +3201,9 @@ Base and mixin classes
31503201

31513202
Same as :meth:`Misc.grid_size`: return a ``(columns, rows)`` tuple giving
31523203
the size of the grid.
3153-
:meth:`size` is an alias of :meth:`!grid_size`.
3204+
:meth:`size` is an alias of :meth:`!grid_size`,
3205+
except on the :class:`Listbox` widget,
3206+
which provides its own :meth:`!size` method.
31543207

31553208
.. method:: propagate()
31563209
propagate(flag)
@@ -3160,7 +3213,6 @@ Base and mixin classes
31603213
grid_propagate(flag)
31613214

31623215
Same as :meth:`Misc.grid_propagate`.
3163-
:meth:`propagate` is an alias of :meth:`!grid_propagate`.
31643216

31653217
.. method:: slaves(row=None, column=None)
31663218
:no-typesetting:
@@ -3169,7 +3221,6 @@ Base and mixin classes
31693221

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

31743225

31753226
.. class:: XView()
@@ -3769,6 +3820,14 @@ Widget classes
37693820
This has no effect on embedded window items.
37703821
:meth:`lower` is an alias of :meth:`!tag_lower`.
37713822

3823+
.. note::
3824+
3825+
On a :class:`Canvas`, :meth:`tkraise`/:meth:`lift` and :meth:`lower`
3826+
restack canvas items,
3827+
shadowing the inherited :meth:`Misc.tkraise`/:meth:`Misc.lift` and
3828+
:meth:`Misc.lower` methods that restack the widget itself,
3829+
which are therefore not available.
3830+
37723831
.. method:: tag_bind(tagOrId, sequence=None, func=None, add=None)
37733832

37743833
Bind the callback *func* to the event *sequence* for all items given by
@@ -3804,6 +3863,9 @@ Widget classes
38043863
Return ``None`` if no item matches or the matching items have nothing to
38053864
display.
38063865

3866+
This shadows the inherited :meth:`!Misc.bbox`;
3867+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
3868+
38073869
.. method:: canvasx(screenx, gridspacing=None)
38083870

38093871
Given a window x-coordinate *screenx*, return the canvas x-coordinate
@@ -3830,6 +3892,9 @@ Widget classes
38303892
An item only displays the insertion cursor when both it is the focus item
38313893
and its canvas has the input focus.
38323894

3895+
This shadows the inherited :meth:`!Misc.focus`;
3896+
use :meth:`~Misc.focus_set` to focus the widget itself.
3897+
38333898
.. method:: icursor(tagOrId, index, /)
38343899

38353900
Set the insertion cursor of the items given by *tagOrId* to just before
@@ -4027,6 +4092,12 @@ Widget classes
40274092
If the selection is not in this widget the method has no effect.
40284093
:meth:`select_clear` is an alias of :meth:`!selection_clear`.
40294094

4095+
.. note::
4096+
4097+
This shadows the inherited :meth:`Misc.selection_clear`,
4098+
which clears the X selection;
4099+
that method is not available on an :class:`Entry`.
4100+
40304101
.. method:: select_from(index)
40314102
:no-typesetting:
40324103

@@ -4166,6 +4237,9 @@ Widget classes
41664237

41674238
Return the total number of items in the listbox.
41684239

4240+
This shadows the inherited :meth:`!Misc.size`;
4241+
use :meth:`~Misc.grid_size` for the grid size.
4242+
41694243
.. method:: index(index)
41704244

41714245
Return the integer index value corresponding to *index*, or ``None`` if
@@ -4182,6 +4256,9 @@ Widget classes
41824256
visible, the result still gives the full area of the item, including the
41834257
parts that are not visible.
41844258

4259+
This shadows the inherited :meth:`!Misc.bbox`;
4260+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
4261+
41854262
.. method:: nearest(y)
41864263

41874264
Given a y-coordinate within the listbox window, return the index of the
@@ -4230,6 +4307,12 @@ Widget classes
42304307
The selection state of items outside this range is not changed.
42314308
:meth:`select_clear` is an alias of :meth:`!selection_clear`.
42324309

4310+
.. note::
4311+
4312+
This shadows the inherited :meth:`Misc.selection_clear`,
4313+
which clears the X selection;
4314+
that method is not available on a :class:`Listbox`.
4315+
42334316
.. method:: select_includes(index)
42344317
:no-typesetting:
42354318

@@ -4614,6 +4697,9 @@ Widget classes
46144697
Remove the pane containing *child* from the panedwindow.
46154698
All geometry management options for *child* are forgotten.
46164699
:meth:`forget` is an alias of :meth:`!remove`.
4700+
This shadows the inherited geometry-manager :meth:`!forget`;
4701+
use :meth:`~Pack.pack_forget`, :meth:`~Grid.grid_forget` or
4702+
:meth:`~Place.place_forget` to remove the widget itself from its manager.
46174703

46184704
.. method:: panes()
46194705

@@ -4905,6 +4991,9 @@ Widget classes
49054991
The bounding box may refer to a region outside the visible area of the
49064992
window.
49074993

4994+
This shadows the inherited :meth:`!Misc.bbox`;
4995+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
4996+
49084997
.. method:: identify(x, y)
49094998

49104999
Return the name of the window element at the pixel coordinates *x*, *y*:
@@ -4966,6 +5055,12 @@ Widget classes
49665055
Clear the selection if it is currently in this widget.
49675056
If the selection is not in this widget, the method has no effect.
49685057

5058+
.. note::
5059+
5060+
This shadows the inherited :meth:`Misc.selection_clear`,
5061+
which clears the X selection;
5062+
that method is not available on a :class:`Spinbox`.
5063+
49695064
.. method:: selection_element(element=None)
49705065

49715066
Set or get the currently selected element.
@@ -5123,6 +5218,9 @@ Widget classes
51235218
pixels, of the visible part of the character at *index*, or ``None`` if
51245219
that character is not visible on the screen.
51255220

5221+
This shadows the inherited :meth:`!Misc.bbox`;
5222+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
5223+
51265224
.. method:: dlineinfo(index)
51275225

51285226
Return a tuple ``(x, y, width, height, baseline)`` describing the display
@@ -5377,6 +5475,12 @@ Widget classes
53775475

53785476
Return a tuple of the names of all images embedded in the widget.
53795477

5478+
.. note::
5479+
5480+
This shadows the inherited :meth:`Misc.image_names`,
5481+
which returns the names of all images in the Tcl interpreter;
5482+
that method is not available on a :class:`Text`.
5483+
53805484
.. method:: window_create(index, cnf={}, **kw)
53815485

53825486
Embed a window (any widget) at *index*.
@@ -5567,6 +5671,7 @@ Variable classes
55675671
.. method:: set(value)
55685672

55695673
Set the variable to *value*.
5674+
:meth:`initialize` is an alias of :meth:`!set`.
55705675

55715676
.. versionadded:: 3.3
55725677
The *initialize* spelling.
@@ -5613,6 +5718,7 @@ Variable classes
56135718
*mode* is one of the strings ``'r'``, ``'w'`` or ``'u'``, for read, write
56145719
or unset.
56155720
Return the internal name of the registered callback.
5721+
:meth:`trace` is an alias of :meth:`!trace_variable`.
56165722

56175723
.. deprecated:: 3.6
56185724
Use :meth:`trace_add` instead. This method wraps a Tcl feature that
@@ -5684,6 +5790,7 @@ Variable classes
56845790
.. method:: set(value)
56855791

56865792
Set the variable to *value*, converting it to a boolean.
5793+
:meth:`initialize` is an alias of :meth:`!set`.
56875794

56885795
.. versionadded:: 3.3
56895796
The *initialize* spelling.

0 commit comments

Comments
 (0)