Skip to content

Commit f5fa057

Browse files
gh-50409: Modernize tkinter.PanedWindow.paneconfigure()
Rename the first parameter of paneconfigure() (and its paneconfig alias) from 'tagOrId' to 'child', for consistency with add(), remove() and panecget() -- PanedWindow panes are child widgets, not tagged items. The old 'tagOrId' keyword still works but raises DeprecationWarning. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3fa72d5 commit f5fa057

4 files changed

Lines changed: 51 additions & 7 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,13 +4895,13 @@ Widget classes
48954895
containing *child*.
48964896
*option* may be any value allowed by :meth:`paneconfigure`.
48974897

4898-
.. method:: paneconfig(tagOrId, cnf=None, **kw)
4898+
.. method:: paneconfig(child, cnf=None, **kw)
48994899
:no-typesetting:
49004900

4901-
.. method:: paneconfigure(tagOrId, cnf=None, **kw)
4901+
.. method:: paneconfigure(child, cnf=None, **kw)
49024902

49034903
Query or modify the management options of the pane containing the widget
4904-
*tagOrId*.
4904+
*child*.
49054905
With no options, it returns a dictionary describing all of the available
49064906
options for the pane; given a single option name as a string, it returns
49074907
a description of that one option; otherwise it sets the given options.
@@ -4916,6 +4916,11 @@ Widget classes
49164916
``'always'``, ``'first'``, ``'last'``, ``'middle'`` or ``'never'``).
49174917
:meth:`paneconfig` is an alias of :meth:`!paneconfigure`.
49184918

4919+
.. versionchanged:: next
4920+
The first parameter was renamed from *tagOrId* to *child*.
4921+
The old name is still accepted as a keyword argument,
4922+
but it is deprecated and will be removed in Python 3.18.
4923+
49194924
.. method:: identify(x, y)
49204925

49214926
Identify the panedwindow component underneath the point given by *x* and

Lib/test/test_tkinter/test_widgets.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,27 @@ def test_paneconfigure_width(self):
23912391
self.check_paneconfigure_bad(p, b, 'width',
23922392
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG.format('badValue'))
23932393

2394+
def test_paneconfigure_child(self):
2395+
p, b, c = self.create2()
2396+
# The child pane is the first argument, positionally or by keyword.
2397+
p.paneconfigure(b, minsize=40)
2398+
self.assertEqual(p.panecget(b, 'minsize'), 40)
2399+
p.paneconfigure(child=b, minsize=50)
2400+
self.assertEqual(p.panecget(b, 'minsize'), 50)
2401+
self.assertIsInstance(p.paneconfigure(b), dict)
2402+
self.assertEqual(p.paneconfigure(b, 'minsize')[4], 50)
2403+
# Omitting the child is an error.
2404+
self.assertRaises(TypeError, p.paneconfigure)
2405+
2406+
def test_paneconfigure_tagOrId_deprecated(self):
2407+
p, b, c = self.create2()
2408+
# 'tagOrId' is a deprecated alias of 'child'.
2409+
with self.assertWarns(DeprecationWarning):
2410+
p.paneconfigure(tagOrId=b, minsize=40)
2411+
self.assertEqual(p.panecget(b, 'minsize'), 40)
2412+
# Giving both 'child' and 'tagOrId' is an error.
2413+
self.assertRaises(TypeError, p.paneconfigure, b, tagOrId=c)
2414+
23942415

23952416
@add_configure_tests(StandardOptionsTests)
23962417
class MenuTest(AbstractWidgetTest, unittest.TestCase):

Lib/tkinter/__init__.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5293,7 +5293,7 @@ def panecget(self, child, option):
52935293
return self.tk.call(
52945294
(self._w, 'panecget') + (child, '-'+option))
52955295

5296-
def paneconfigure(self, tagOrId, cnf=None, **kw):
5296+
def paneconfigure(self, child=None, cnf=None, **kw):
52975297
"""Query or modify the configuration options for a child window.
52985298
52995299
Similar to configure() except that it applies to the specified
@@ -5355,12 +5355,26 @@ def paneconfigure(self, tagOrId, cnf=None, **kw):
53555355
Tk_GetPixels.
53565356
53575357
"""
5358+
if 'tagOrId' in kw:
5359+
if child is not None:
5360+
raise TypeError("paneconfigure() got values for both 'child' "
5361+
"and its deprecated alias 'tagOrId'")
5362+
import warnings
5363+
warnings.warn(
5364+
"The 'tagOrId' parameter of PanedWindow.paneconfigure() "
5365+
"is deprecated and will be removed in Python 3.18; "
5366+
"use 'child' instead.",
5367+
DeprecationWarning, stacklevel=2)
5368+
child = kw.pop('tagOrId')
5369+
if child is None:
5370+
raise TypeError("paneconfigure() missing 1 required positional "
5371+
"argument: 'child'")
53585372
if cnf is None and not kw:
5359-
return self._getconfigure(self._w, 'paneconfigure', tagOrId)
5373+
return self._getconfigure(self._w, 'paneconfigure', child)
53605374
if isinstance(cnf, str) and not kw:
53615375
return self._getconfigure1(
5362-
self._w, 'paneconfigure', tagOrId, '-'+cnf)
5363-
self.tk.call((self._w, 'paneconfigure', tagOrId) +
5376+
self._w, 'paneconfigure', child, '-'+cnf)
5377+
self.tk.call((self._w, 'paneconfigure', child) +
53645378
self._options(cnf, kw))
53655379

53665380
paneconfig = paneconfigure
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecate the *tagOrId* parameter of
2+
:meth:`!tkinter.PanedWindow.paneconfigure` (and its :meth:`!paneconfig`
3+
alias) in favor of *child*, for consistency with the other pane methods;
4+
it will be removed in Python 3.18.

0 commit comments

Comments
 (0)