Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81d2be9

Browse files
Issue #19020: Tkinter now uses splitlist() instead of split() in configure
methods.
2 parents a7a4b49 + 848972c commit 81d2be9

4 files changed

Lines changed: 34 additions & 54 deletions

File tree

Lib/tkinter/__init__.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,22 +1235,29 @@ def _report_exception(self):
12351235
exc, val, tb = sys.exc_info()
12361236
root = self._root()
12371237
root.report_callback_exception(exc, val, tb)
1238+
1239+
def _getconfigure(self, *args):
1240+
"""Call Tcl configure command and return the result as a dict."""
1241+
cnf = {}
1242+
for x in self.tk.splitlist(self.tk.call(*args)):
1243+
x = self.tk.splitlist(x)
1244+
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
1245+
return cnf
1246+
1247+
def _getconfigure1(self, *args):
1248+
x = self.tk.splitlist(self.tk.call(*args))
1249+
return (x[0][1:],) + x[1:]
1250+
12381251
def _configure(self, cmd, cnf, kw):
12391252
"""Internal function."""
12401253
if kw:
12411254
cnf = _cnfmerge((cnf, kw))
12421255
elif cnf:
12431256
cnf = _cnfmerge(cnf)
12441257
if cnf is None:
1245-
cnf = {}
1246-
for x in self.tk.split(
1247-
self.tk.call(_flatten((self._w, cmd)))):
1248-
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
1249-
return cnf
1258+
return self._getconfigure(_flatten((self._w, cmd)))
12501259
if isinstance(cnf, str):
1251-
x = self.tk.split(
1252-
self.tk.call(_flatten((self._w, cmd, '-'+cnf))))
1253-
return (x[0][1:],) + x[1:]
1260+
return self._getconfigure1(_flatten((self._w, cmd, '-'+cnf)))
12541261
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
12551262
# These used to be defined in Widget:
12561263
def configure(self, cnf=None, **kw):
@@ -1271,7 +1278,7 @@ def __setitem__(self, key, value):
12711278
def keys(self):
12721279
"""Return a list of all resource names of this widget."""
12731280
return [x[0][1:] for x in
1274-
self.tk.split(self.tk.call(self._w, 'configure'))]
1281+
self.tk.splitlist(self.tk.call(self._w, 'configure'))]
12751282
def __str__(self):
12761283
"""Return the window path name of this widget."""
12771284
return self._w
@@ -3786,16 +3793,10 @@ def paneconfigure(self, tagOrId, cnf=None, **kw):
37863793
37873794
"""
37883795
if cnf is None and not kw:
3789-
cnf = {}
3790-
for x in self.tk.split(
3791-
self.tk.call(self._w,
3792-
'paneconfigure', tagOrId)):
3793-
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
3794-
return cnf
3796+
return self._getconfigure(self._w, 'paneconfigure', tagOrId)
37953797
if isinstance(cnf, str) and not kw:
3796-
x = self.tk.split(self.tk.call(
3797-
self._w, 'paneconfigure', tagOrId, '-'+cnf))
3798-
return (x[0][1:],) + x[1:]
3798+
return self._getconfigure1(
3799+
self._w, 'paneconfigure', tagOrId, '-'+cnf)
37993800
self.tk.call((self._w, 'paneconfigure', tagOrId) +
38003801
self._options(cnf, kw))
38013802
paneconfig = paneconfigure

Lib/tkinter/test/widget_tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def checkParam(self, widget, name, value, *, expected=_sentinel,
6262
if not isinstance(widget, Scale):
6363
t = widget.configure(name)
6464
self.assertEqual(len(t), 5)
65-
## XXX
66-
if not isinstance(t[4], tuple):
67-
self.assertEqual2(t[4], expected, eq=eq)
65+
self.assertEqual2(t[4], expected, eq=eq)
6866

6967
def checkInvalidParam(self, widget, name, value, errmsg=None, *,
7068
keep_orig=True):

Lib/tkinter/tix.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,9 @@ def tix_configure(self, cnf=None, **kw):
122122
elif cnf:
123123
cnf = _cnfmerge(cnf)
124124
if cnf is None:
125-
cnf = {}
126-
for x in self.tk.split(self.tk.call('tix', 'configure')):
127-
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
128-
return cnf
125+
return self._getconfigure('tix', 'configure')
129126
if isinstance(cnf, str):
130-
x = self.tk.split(self.tk.call('tix', 'configure', '-'+cnf))
131-
return (x[0][1:],) + x[1:]
127+
return self._getconfigure1('tix', 'configure', '-'+cnf)
132128
return self.tk.call(('tix', 'configure') + self._options(cnf))
133129

134130
def tix_filedialog(self, dlgclass=None):
@@ -380,7 +376,7 @@ def _subwidget_names(self):
380376
"""Return the name of all subwidgets."""
381377
try:
382378
x = self.tk.call(self._w, 'subwidgets', '-all')
383-
return self.tk.split(x)
379+
return self.tk.splitlist(x)
384380
except TclError:
385381
return None
386382

@@ -473,13 +469,6 @@ def destroy(self):
473469
self.tk.call('destroy', self._w)
474470

475471

476-
# Useful func. to split Tcl lists and return as a dict. From Tkinter.py
477-
def _lst2dict(lst):
478-
dict = {}
479-
for x in lst:
480-
dict[x[0][1:]] = (x[0][1:],) + x[1:]
481-
return dict
482-
483472
# Useful class to create a display style - later shared by many items.
484473
# Contributed by Steffen Kremser
485474
class DisplayStyle:
@@ -515,10 +504,8 @@ def __setitem__(self,key,value):
515504
self.tk.call(self.stylename, 'configure', '-%s'%key, value)
516505

517506
def config(self, cnf={}, **kw):
518-
return _lst2dict(
519-
self.tk.split(
520-
self.tk.call(
521-
self.stylename, 'configure', *self._options(cnf,kw))))
507+
return self._getconfigure(
508+
self.stylename, 'configure', *self._options(cnf,kw))
522509

523510
def __getitem__(self,key):
524511
return self.tk.call(self.stylename, 'cget', '-%s'%key)
@@ -928,9 +915,7 @@ def header_create(self, col, cnf={}, **kw):
928915

929916
def header_configure(self, col, cnf={}, **kw):
930917
if cnf is None:
931-
return _lst2dict(
932-
self.tk.split(
933-
self.tk.call(self._w, 'header', 'configure', col)))
918+
return self._getconfigure(self._w, 'header', 'configure', col)
934919
self.tk.call(self._w, 'header', 'configure', col,
935920
*self._options(cnf, kw))
936921

@@ -955,9 +940,8 @@ def indicator_create(self, entry, cnf={}, **kw):
955940

956941
def indicator_configure(self, entry, cnf={}, **kw):
957942
if cnf is None:
958-
return _lst2dict(
959-
self.tk.split(
960-
self.tk.call(self._w, 'indicator', 'configure', entry)))
943+
return self._getconfigure(
944+
self._w, 'indicator', 'configure', entry)
961945
self.tk.call(
962946
self._w, 'indicator', 'configure', entry, *self._options(cnf, kw))
963947

@@ -1017,9 +1001,7 @@ def item_cget(self, entry, col, opt):
10171001

10181002
def item_configure(self, entry, col, cnf={}, **kw):
10191003
if cnf is None:
1020-
return _lst2dict(
1021-
self.tk.split(
1022-
self.tk.call(self._w, 'item', 'configure', entry, col)))
1004+
return self._getconfigure(self._w, 'item', 'configure', entry, col)
10231005
self.tk.call(self._w, 'item', 'configure', entry, col,
10241006
*self._options(cnf, kw))
10251007

@@ -1038,9 +1020,7 @@ def entrycget(self, entry, opt):
10381020

10391021
def entryconfigure(self, entry, cnf={}, **kw):
10401022
if cnf is None:
1041-
return _lst2dict(
1042-
self.tk.split(
1043-
self.tk.call(self._w, 'entryconfigure', entry)))
1023+
return self._getconfigure(self._w, 'entryconfigure', entry)
10441024
self.tk.call(self._w, 'entryconfigure', entry,
10451025
*self._options(cnf, kw))
10461026

@@ -1254,9 +1234,7 @@ def panecget(self, entry, opt):
12541234

12551235
def paneconfigure(self, entry, cnf={}, **kw):
12561236
if cnf is None:
1257-
return _lst2dict(
1258-
self.tk.split(
1259-
self.tk.call(self._w, 'paneconfigure', entry)))
1237+
return self._getconfigure(self._w, 'paneconfigure', entry)
12601238
self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
12611239

12621240
def panes(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #19020: Tkinter now uses splitlist() instead of split() in configure
48+
methods.
49+
4750
- Issue #19744: ensurepip now provides a better error message when Python is
4851
built without SSL/TLS support (pip currently requires that support to run,
4952
even if only operating with local wheel files)

0 commit comments

Comments
 (0)