Skip to content

Commit 26e5c28

Browse files
gh-86726: Document tkinter method-name conflicts
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. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XWevzas4XVpjzedzR9gKVo
1 parent f28ef85 commit 26e5c28

4 files changed

Lines changed: 155 additions & 32 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 117 additions & 15 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

@@ -1681,7 +1695,10 @@ Base and mixin classes
16811695
widget's display, the widget is remembered as the focus window for its
16821696
top level, and the focus will be redirected to it the next time the
16831697
window manager gives the focus to the top level.
1684-
:meth:`focus` is an alias of :meth:`!focus_set`.
1698+
:meth:`focus` is an alias of :meth:`!focus_set`,
1699+
except on the :class:`Canvas` and
1700+
:class:`ttk.Treeview <tkinter.ttk.Treeview>` widgets,
1701+
which provide their own :meth:`!focus` method.
16851702

16861703
.. method:: focus_force()
16871704

@@ -1783,6 +1800,10 @@ Base and mixin classes
17831800
The *displayof* keyword argument names a widget that determines the
17841801
display on which to operate, and defaults to this widget.
17851802

1803+
This is overridden by the :class:`Entry`, :class:`Listbox` and
1804+
:class:`Spinbox` widgets,
1805+
where :meth:`!selection_clear` clears the widget's own selection instead.
1806+
17861807
.. method:: selection_get(**kw)
17871808

17881809
Return the contents of the current X selection.
@@ -2546,6 +2567,8 @@ Base and mixin classes
25462567
widget is managed again.
25472568
:meth:`wm_forget` is an alias of :meth:`!forget`.
25482569

2570+
Not to be confused with :meth:`Pack.forget`.
2571+
25492572
.. versionadded:: 3.3
25502573

25512574
.. method:: wm_frame()
@@ -2591,6 +2614,8 @@ Base and mixin classes
25912614
string if the window is not gridded.
25922615
:meth:`wm_grid` is an alias of :meth:`!grid`.
25932616

2617+
Not to be confused with the grid geometry manager :meth:`Grid.grid`.
2618+
25942619
.. method:: wm_group(pathName=None)
25952620
:no-typesetting:
25962621

@@ -2828,6 +2853,9 @@ Base and mixin classes
28282853
:meth:`iconwindow`); the ``'icon'`` state cannot be set.
28292854
:meth:`wm_state` is an alias of :meth:`!state`.
28302855

2856+
Not to be confused with :meth:`ttk.Widget.state
2857+
<tkinter.ttk.Widget.state>`.
2858+
28312859
.. method:: wm_title(string=None)
28322860
:no-typesetting:
28332861

@@ -2879,6 +2907,21 @@ Base and mixin classes
28792907
*pack* geometry manager.
28802908
See also :ref:`pack-the-packer`.
28812909

2910+
.. note::
2911+
2912+
:class:`Pack`, :class:`Place` and :class:`Grid` all define the short
2913+
method names :meth:`!forget`, :meth:`!info`, :meth:`!slaves`,
2914+
:meth:`!content` and :meth:`!propagate`.
2915+
On a widget the bare names resolve to the *pack* manager's versions,
2916+
since :class:`Pack` and :class:`Misc` precede :class:`Place` and
2917+
:class:`Grid` in the method resolution order,
2918+
whatever manager actually manages the widget;
2919+
and :meth:`!configure`/:meth:`!config` configure the widget's options,
2920+
not its geometry.
2921+
Use the explicit ``pack_*``, ``grid_*`` and ``place_*`` methods
2922+
(and ``pack``, ``grid``, ``place`` for geometry configuration)
2923+
to act on a specific geometry manager.
2924+
28822925
.. method:: configure(cnf={}, **kw)
28832926
:no-typesetting:
28842927

@@ -2941,7 +2984,13 @@ Base and mixin classes
29412984
Unmap the widget and remove it from the packing order, forgetting its
29422985
packing options.
29432986
It can be packed again later with :meth:`pack_configure`.
2944-
:meth:`forget` is an alias of :meth:`!pack_forget`.
2987+
:meth:`forget` is an alias of :meth:`!pack_forget`,
2988+
except on :class:`PanedWindow`,
2989+
:class:`ttk.Notebook <tkinter.ttk.Notebook>` and
2990+
:class:`ttk.PanedWindow <tkinter.ttk.PanedWindow>`,
2991+
which provide their own :meth:`!forget` method.
2992+
2993+
Not to be confused with :meth:`Wm.forget`.
29452994

29462995
.. method:: info()
29472996
:no-typesetting:
@@ -3048,15 +3097,13 @@ Base and mixin classes
30483097

30493098
Unmap the widget and remove it from the placement, forgetting its place
30503099
options.
3051-
:meth:`forget` is an alias of :meth:`!place_forget`.
30523100

30533101
.. method:: info()
30543102
:no-typesetting:
30553103

30563104
.. method:: place_info()
30573105

30583106
Return a dictionary of the widget's current place options.
3059-
:meth:`info` is an alias of :meth:`!place_info`.
30603107

30613108
.. method:: slaves()
30623109
:no-typesetting:
@@ -3065,15 +3112,13 @@ Base and mixin classes
30653112

30663113
Same as :meth:`Misc.place_slaves`: return the list of widgets placed in
30673114
this widget.
3068-
:meth:`slaves` is an alias of :meth:`!place_slaves`.
30693115

30703116
.. method:: content()
30713117
:no-typesetting:
30723118

30733119
.. method:: place_content()
30743120

30753121
Same as :meth:`Misc.place_content`.
3076-
:meth:`content` is an alias of :meth:`!place_content`.
30773122

30783123
.. versionadded:: 3.15
30793124

@@ -3095,6 +3140,9 @@ Base and mixin classes
30953140
grid(cnf={}, **kw)
30963141
30973142
Position the widget in a cell of its container's grid.
3143+
3144+
Not to be confused with :meth:`Wm.grid`.
3145+
30983146
The supported options are:
30993147

31003148
*row*, *column*
@@ -3139,7 +3187,6 @@ Base and mixin classes
31393187

31403188
Unmap the widget and remove it from the grid, forgetting its grid
31413189
options.
3142-
:meth:`forget` is an alias of :meth:`!grid_forget`.
31433190

31443191
.. method:: grid_remove()
31453192

@@ -3152,15 +3199,18 @@ Base and mixin classes
31523199
.. method:: grid_info()
31533200

31543201
Return a dictionary of the widget's current grid options.
3155-
:meth:`info` is an alias of :meth:`!grid_info`.
31563202

31573203
.. method:: bbox(column=None, row=None, col2=None, row2=None)
31583204
:no-typesetting:
31593205

31603206
.. method:: grid_bbox(column=None, row=None, col2=None, row2=None)
31613207

31623208
Same as :meth:`Misc.grid_bbox`.
3163-
:meth:`bbox` is an alias of :meth:`!grid_bbox`.
3209+
:meth:`bbox` is an alias of :meth:`!grid_bbox`,
3210+
except on :class:`Canvas`, :class:`Listbox`, :class:`Spinbox`,
3211+
:class:`Text`, :class:`ttk.Entry <tkinter.ttk.Entry>` and
3212+
:class:`ttk.Treeview <tkinter.ttk.Treeview>`,
3213+
which provide their own :meth:`!bbox` method.
31643214

31653215
.. method:: columnconfigure(index, cnf={}, **kw)
31663216
:no-typesetting:
@@ -3196,7 +3246,9 @@ Base and mixin classes
31963246

31973247
Same as :meth:`Misc.grid_size`: return a ``(columns, rows)`` tuple giving
31983248
the size of the grid.
3199-
:meth:`size` is an alias of :meth:`!grid_size`.
3249+
:meth:`size` is an alias of :meth:`!grid_size`,
3250+
except on the :class:`Listbox` widget,
3251+
which provides its own :meth:`!size` method.
32003252

32013253
.. method:: propagate()
32023254
propagate(flag)
@@ -3206,7 +3258,6 @@ Base and mixin classes
32063258
grid_propagate(flag)
32073259

32083260
Same as :meth:`Misc.grid_propagate`.
3209-
:meth:`propagate` is an alias of :meth:`!grid_propagate`.
32103261

32113262
.. method:: slaves(row=None, column=None)
32123263
:no-typesetting:
@@ -3215,15 +3266,13 @@ Base and mixin classes
32153266

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

32203270
.. method:: content(row=None, column=None)
32213271
:no-typesetting:
32223272

32233273
.. method:: grid_content(row=None, column=None)
32243274

32253275
Same as :meth:`Misc.grid_content`.
3226-
:meth:`content` is an alias of :meth:`!grid_content`.
32273276

32283277
.. versionadded:: 3.15
32293278

@@ -3825,6 +3874,14 @@ Widget classes
38253874
This has no effect on embedded window items.
38263875
:meth:`lower` is an alias of :meth:`!tag_lower`.
38273876

3877+
.. note::
3878+
3879+
On a :class:`Canvas`, :meth:`tkraise`/:meth:`lift` and :meth:`lower`
3880+
restack canvas items,
3881+
shadowing the inherited :meth:`Misc.tkraise`/:meth:`Misc.lift` and
3882+
:meth:`Misc.lower` methods that restack the widget itself,
3883+
which are therefore not available.
3884+
38283885
.. method:: tag_bind(tagOrId, sequence=None, func=None, add=None)
38293886

38303887
Bind the callback *func* to the event *sequence* for all items given by
@@ -3860,6 +3917,9 @@ Widget classes
38603917
Return ``None`` if no item matches or the matching items have nothing to
38613918
display.
38623919

3920+
This shadows the inherited :meth:`!Misc.bbox`;
3921+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
3922+
38633923
.. method:: canvasx(screenx, gridspacing=None)
38643924

38653925
Given a window x-coordinate *screenx*, return the canvas x-coordinate
@@ -3886,6 +3946,9 @@ Widget classes
38863946
An item only displays the insertion cursor when both it is the focus item
38873947
and its canvas has the input focus.
38883948

3949+
This shadows the inherited :meth:`!Misc.focus`;
3950+
use :meth:`~Misc.focus_set` to focus the widget itself.
3951+
38893952
.. method:: icursor(tagOrId, index, /)
38903953

38913954
Set the insertion cursor of the items given by *tagOrId* to just before
@@ -4083,6 +4146,12 @@ Widget classes
40834146
If the selection is not in this widget the method has no effect.
40844147
:meth:`select_clear` is an alias of :meth:`!selection_clear`.
40854148

4149+
.. note::
4150+
4151+
This shadows the inherited :meth:`Misc.selection_clear`,
4152+
which clears the X selection;
4153+
that method is not available on an :class:`Entry`.
4154+
40864155
.. method:: select_from(index)
40874156
:no-typesetting:
40884157

@@ -4222,6 +4291,9 @@ Widget classes
42224291

42234292
Return the total number of items in the listbox.
42244293

4294+
This shadows the inherited :meth:`!Misc.size`;
4295+
use :meth:`~Misc.grid_size` for the grid size.
4296+
42254297
.. method:: index(index)
42264298

42274299
Return the integer index value corresponding to *index*, or ``None`` if
@@ -4238,6 +4310,9 @@ Widget classes
42384310
visible, the result still gives the full area of the item, including the
42394311
parts that are not visible.
42404312

4313+
This shadows the inherited :meth:`!Misc.bbox`;
4314+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
4315+
42414316
.. method:: nearest(y)
42424317

42434318
Given a y-coordinate within the listbox window, return the index of the
@@ -4286,6 +4361,12 @@ Widget classes
42864361
The selection state of items outside this range is not changed.
42874362
:meth:`select_clear` is an alias of :meth:`!selection_clear`.
42884363

4364+
.. note::
4365+
4366+
This shadows the inherited :meth:`Misc.selection_clear`,
4367+
which clears the X selection;
4368+
that method is not available on a :class:`Listbox`.
4369+
42894370
.. method:: select_includes(index)
42904371
:no-typesetting:
42914372

@@ -4670,6 +4751,9 @@ Widget classes
46704751
Remove the pane containing *child* from the panedwindow.
46714752
All geometry management options for *child* are forgotten.
46724753
:meth:`forget` is an alias of :meth:`!remove`.
4754+
This shadows the inherited geometry-manager :meth:`!forget`;
4755+
use :meth:`~Pack.pack_forget`, :meth:`~Grid.grid_forget` or
4756+
:meth:`~Place.place_forget` to remove the widget itself from its manager.
46734757

46744758
.. method:: panes()
46754759

@@ -4961,6 +5045,9 @@ Widget classes
49615045
The bounding box may refer to a region outside the visible area of the
49625046
window.
49635047

5048+
This shadows the inherited :meth:`!Misc.bbox`;
5049+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
5050+
49645051
.. method:: identify(x, y)
49655052

49665053
Return the name of the window element at the pixel coordinates *x*, *y*:
@@ -5022,6 +5109,12 @@ Widget classes
50225109
Clear the selection if it is currently in this widget.
50235110
If the selection is not in this widget, the method has no effect.
50245111

5112+
.. note::
5113+
5114+
This shadows the inherited :meth:`Misc.selection_clear`,
5115+
which clears the X selection;
5116+
that method is not available on a :class:`Spinbox`.
5117+
50255118
.. method:: selection_element(element=None)
50265119

50275120
Set or get the currently selected element.
@@ -5179,6 +5272,9 @@ Widget classes
51795272
pixels, of the visible part of the character at *index*, or ``None`` if
51805273
that character is not visible on the screen.
51815274

5275+
This shadows the inherited :meth:`!Misc.bbox`;
5276+
use :meth:`~Misc.grid_bbox` for the grid bounding box.
5277+
51825278
.. method:: dlineinfo(index)
51835279

51845280
Return a tuple ``(x, y, width, height, baseline)`` describing the display
@@ -5433,6 +5529,12 @@ Widget classes
54335529

54345530
Return a tuple of the names of all images embedded in the widget.
54355531

5532+
.. note::
5533+
5534+
This shadows the inherited :meth:`Misc.image_names`,
5535+
which returns the names of all images in the Tcl interpreter;
5536+
that method is not available on a :class:`Text`.
5537+
54365538
.. method:: window_create(index, cnf={}, **kw)
54375539

54385540
Embed a window (any widget) at *index*.

0 commit comments

Comments
 (0)