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 da8825e

Browse filesBrowse files
authored
gh-128562: Fix generation of the tkinter widget names (GH-128604)
There were possible conflicts if the widget class name ends with a digit.
1 parent 402b91d commit da8825e
Copy full SHA for da8825e

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
@@ -31,12 +31,20 @@ def test_repr(self):
3131
self.assertEqual(repr(f), '<tkinter.Frame object .top.child>')
3232

3333
def test_generated_names(self):
34+
class Button2(tkinter.Button):
35+
pass
36+
3437
t = tkinter.Toplevel(self.root)
3538
f = tkinter.Frame(t)
3639
f2 = tkinter.Frame(t)
40+
self.assertNotEqual(str(f), str(f2))
3741
b = tkinter.Button(f2)
38-
for name in str(b).split('.'):
42+
b2 = Button2(f2)
43+
for name in str(b).split('.') + str(b2).split('.'):
3944
self.assertFalse(name.isidentifier(), msg=repr(name))
45+
b3 = tkinter.Button(f2)
46+
b4 = Button2(f2)
47+
self.assertEqual(len({str(b), str(b2), str(b3), str(b4)}), 4)
4048

4149
@requires_tk(8, 6, 6)
4250
def test_tk_busy(self):

‎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
@@ -2741,6 +2741,8 @@ def _setup(self, master, cnf):
27412741
del cnf['name']
27422742
if not name:
27432743
name = self.__class__.__name__.lower()
2744+
if name[-1].isdigit():
2745+
name += "!" # Avoid duplication when calculating names below
27442746
if master._last_child_ids is None:
27452747
master._last_child_ids = {}
27462748
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.