Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca5ff6b

Browse filesBrowse files
[3.12] gh-128562: Fix generation of the tkinter widget names (GH-128604) (GH-128792)
There were possible conflicts if the widget class name ends with a digit. (cherry picked from commit da8825e) Co-authored-by: Zhikang Yan <2951256653@qq.com>
1 parent 4facd7d commit ca5ff6b
Copy full SHA for ca5ff6b

File tree

Expand file treeCollapse file tree

3 files changed

+12
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-1
lines changed

‎Lib/test/test_tkinter/test_misc.py

Copy file name to clipboardExpand all lines: Lib/test/test_tkinter/test_misc.py
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ def test_repr(self):
3030
self.assertEqual(repr(f), '<tkinter.Frame object .top.child>')
3131

3232
def test_generated_names(self):
33+
class Button2(tkinter.Button):
34+
pass
35+
3336
t = tkinter.Toplevel(self.root)
3437
f = tkinter.Frame(t)
3538
f2 = tkinter.Frame(t)
39+
self.assertNotEqual(str(f), str(f2))
3640
b = tkinter.Button(f2)
37-
for name in str(b).split('.'):
41+
b2 = Button2(f2)
42+
for name in str(b).split('.') + str(b2).split('.'):
3843
self.assertFalse(name.isidentifier(), msg=repr(name))
44+
b3 = tkinter.Button(f2)
45+
b4 = Button2(f2)
46+
self.assertEqual(len({str(b), str(b2), str(b3), str(b4)}), 4)
3947

4048
def test_tk_setPalette(self):
4149
root = self.root

‎Lib/tkinter/__init__.py

Copy file name to clipboardExpand all lines: Lib/tkinter/__init__.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,8 @@ def _setup(self, master, cnf):
26262626
del cnf['name']
26272627
if not name:
26282628
name = self.__class__.__name__.lower()
2629+
if name[-1].isdigit():
2630+
name += "!" # Avoid duplication when calculating names below
26292631
if master._last_child_ids is None:
26302632
master._last_child_ids = {}
26312633
count = master._last_child_ids.get(name, 0) + 1
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix possible conflicts in generated :mod:`tkinter` widget names if the widget class name ends with a digit.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.