bpo-33974: Fix passing special characters to ttk widgets. (GH-7986) · python/cpython@5bb5bbf · GitHub
Skip to content

Commit 5bb5bbf

Browse files
bpo-33974: Fix passing special characters to ttk widgets. (GH-7986)
Fix passing lists and tuples of strings containing special characters '"', '\\', '{', '}' and '\n' as options to tkinter.ttk widgets.
1 parent f874bd1 commit 5bb5bbf

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

Lib/test/test_tcl.py

Lines changed: 37 additions & 0 deletions

Lib/tkinter/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _stringify(value):
6161
if isinstance(value, (list, tuple)):
6262
if len(value) == 1:
6363
value = _stringify(value[0])
64-
if value[0] == '{':
64+
if _magic_re.search(value):
6565
value = '{%s}' % value
6666
else:
6767
value = '{%s}' % _join(value)
@@ -72,7 +72,10 @@ def _stringify(value):
7272
elif _magic_re.search(value):
7373
# add '\' before special characters and spaces
7474
value = _magic_re.sub(r'\\\1', value)
75+
value = value.replace('\n', r'\n')
7576
value = _space_re.sub(r'\\\1', value)
77+
if value[0] == '"':
78+
value = '\\' + value
7679
elif value[0] == '"' or _space_re.search(value):
7780
value = '{%s}' % value
7881
return value
Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)