Skip to content

Commit 93128f5

Browse files
pythongh-50409: Modernize tkinter.PanedWindow.paneconfigure() (pythonGH-152399)
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 f212f21 commit 93128f5

4 files changed

Lines changed: 50 additions & 7 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4938,13 +4938,13 @@ Widget classes
49384938
containing *child*.
49394939
*option* may be any value allowed by :meth:`paneconfigure`.
49404940

4941-
.. method:: paneconfig(tagOrId, cnf=None, **kw)
4941+
.. method:: paneconfig(child, cnf=None, **kw)
49424942
:no-typesetting:
49434943

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

49464946
Query or modify the management options of the pane containing the widget
4947-
*tagOrId*.
4947+
*child*.
49484948
With no options, it returns a dictionary describing all of the available
49494949
options for the pane; given a single option name as a string, it returns
49504950
a description of that one option; otherwise it sets the given options.
@@ -4959,6 +4959,10 @@ Widget classes
49594959
``'always'``, ``'first'``, ``'last'``, ``'middle'`` or ``'never'``).
49604960
:meth:`paneconfig` is an alias of :meth:`!paneconfigure`.
49614961

4962+
.. deprecated-removed:: next 3.18
4963+
The first parameter was renamed from *tagOrId* to *child*.
4964+
The old name is still accepted as a keyword argument.
4965+
49624966
.. method:: identify(x, y)
49634967

49644968
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
@@ -2404,6 +2404,27 @@ def test_paneconfigure_width(self):
24042404
self.check_paneconfigure_bad(p, b, 'width',
24052405
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG.format('badValue'))
24062406

2407+
def test_paneconfigure_child(self):
2408+
p, b, c = self.create2()
2409+
# The child pane is the first argument, positionally or by keyword.
2410+
p.paneconfigure(b, minsize=40)
2411+
self.assertEqual(p.panecget(b, 'minsize'), 40)
2412+
p.paneconfigure(child=b, minsize=50)
2413+
self.assertEqual(p.panecget(b, 'minsize'), 50)
2414+
self.assertIsInstance(p.paneconfigure(b), dict)
2415+
self.assertEqual(p.paneconfigure(b, 'minsize')[4], 50)
2416+
# Omitting the child is an error.
2417+
self.assertRaises(TypeError, p.paneconfigure)
2418+
2419+
def test_paneconfigure_tagOrId_deprecated(self):
2420+
p, b, c = self.create2()
2421+
# 'tagOrId' is a deprecated alias of 'child'.
2422+
with self.assertWarns(DeprecationWarning):
2423+
p.paneconfigure(tagOrId=b, minsize=40)
2424+
self.assertEqual(p.panecget(b, 'minsize'), 40)
2425+
# Giving both 'child' and 'tagOrId' is an error.
2426+
self.assertRaises(TypeError, p.paneconfigure, b, tagOrId=c)
2427+
24072428

24082429
@add_configure_tests(StandardOptionsTests)
24092430
class MenuTest(AbstractWidgetTest, unittest.TestCase):

Lib/tkinter/__init__.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5345,7 +5345,7 @@ def panecget(self, child, option):
53455345
return self.tk.call(
53465346
(self._w, 'panecget') + (child, '-'+option))
53475347

5348-
def paneconfigure(self, tagOrId, cnf=None, **kw):
5348+
def paneconfigure(self, child=None, cnf=None, **kw):
53495349
"""Query or modify the configuration options for a child window.
53505350
53515351
Similar to configure() except that it applies to the specified
@@ -5407,12 +5407,26 @@ def paneconfigure(self, tagOrId, cnf=None, **kw):
54075407
Tk_GetPixels.
54085408
54095409
"""
5410+
if 'tagOrId' in kw:
5411+
if child is not None:
5412+
raise TypeError("paneconfigure() got values for both 'child' "
5413+
"and its deprecated alias 'tagOrId'")
5414+
import warnings
5415+
warnings.warn(
5416+
"The 'tagOrId' parameter of PanedWindow.paneconfigure() "
5417+
"is deprecated and will be removed in Python 3.18; "
5418+
"use 'child' instead.",
5419+
DeprecationWarning, stacklevel=2)
5420+
child = kw.pop('tagOrId')
5421+
if child is None:
5422+
raise TypeError("paneconfigure() missing 1 required positional "
5423+
"argument: 'child'")
54105424
if cnf is None and not kw:
5411-
return self._getconfigure(self._w, 'paneconfigure', tagOrId)
5425+
return self._getconfigure(self._w, 'paneconfigure', child)
54125426
if isinstance(cnf, str) and not kw:
54135427
return self._getconfigure1(
5414-
self._w, 'paneconfigure', tagOrId, '-'+cnf)
5415-
self.tk.call((self._w, 'paneconfigure', tagOrId) +
5428+
self._w, 'paneconfigure', child, '-'+cnf)
5429+
self.tk.call((self._w, 'paneconfigure', child) +
54165430
self._options(cnf, kw))
54175431

54185432
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)