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

Skip to content

Commit e959776

Browse files
Fixed grid_columnconfigure() and grid_rowconfigure() methods of
Tkinter widgets to work in wantobjects=True mode.
1 parent d5c8ce7 commit e959776

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

Lib/tkinter/__init__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,21 @@ def grid_bbox(self, column=None, row=None, col2=None, row2=None):
13391339
args = args + (col2, row2)
13401340
return self._getints(self.tk.call(*args)) or None
13411341
bbox = grid_bbox
1342+
1343+
def _gridconvvalue(self, value):
1344+
if isinstance(value, (str, _tkinter.Tcl_Obj)):
1345+
try:
1346+
svalue = str(value)
1347+
if not svalue:
1348+
return None
1349+
elif '.' in svalue:
1350+
return getdouble(svalue)
1351+
else:
1352+
return getint(svalue)
1353+
except ValueError:
1354+
pass
1355+
return value
1356+
13421357
def _grid_configure(self, command, index, cnf, kw):
13431358
"""Internal function."""
13441359
if isinstance(cnf, str) and not kw:
@@ -1357,22 +1372,14 @@ def _grid_configure(self, command, index, cnf, kw):
13571372
for i in range(0, len(words), 2):
13581373
key = words[i][1:]
13591374
value = words[i+1]
1360-
if not value:
1361-
value = None
1362-
elif '.' in str(value):
1363-
value = getdouble(value)
1364-
else:
1365-
value = getint(value)
1366-
dict[key] = value
1375+
dict[key] = self._gridconvvalue(value)
13671376
return dict
13681377
res = self.tk.call(
13691378
('grid', command, self._w, index)
13701379
+ options)
13711380
if len(options) == 1:
1372-
if not res: return None
1373-
# In Tk 7.5, -width can be a float
1374-
if '.' in res: return getdouble(res)
1375-
return getint(res)
1381+
return self._gridconvvalue(res)
1382+
13761383
def grid_columnconfigure(self, index, cnf={}, **kw):
13771384
"""Configure column INDEX of a grid.
13781385

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #20635: Fixed grid_columnconfigure() and grid_rowconfigure() methods of
24+
Tkinter widgets to work in wantobjects=True mode.
25+
2326
- Issue #19612: On Windows, subprocess.Popen.communicate() now ignores
2427
OSError(22, 'Invalid argument') when writing input data into stdin, whereas
2528
the process already exited.

0 commit comments

Comments
 (0)