Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitae66e17

Browse files
serhiy-storchakamiss-islington
authored andcommitted
pythongh-116484: Fix collisions between Checkbutton and ttk.Checkbutton default names (pythonGH-116495)
Change automatically generated tkinter.Checkbutton widget names toavoid collisions with automatically generated tkinter.ttk.Checkbuttonwidget names within the same parent widget.(cherry picked from commitc61cb50)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parenteddfdb3 commitae66e17

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

‎Lib/tkinter/__init__.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3073,11 +3073,16 @@ def __init__(self, master=None, cnf={}, **kw):
30733073
Widget.__init__(self,master,'checkbutton',cnf,kw)
30743074

30753075
def_setup(self,master,cnf):
3076+
# Because Checkbutton defaults to a variable with the same name as
3077+
# the widget, Checkbutton default names must be globally unique,
3078+
# not just unique within the parent widget.
30763079
ifnotcnf.get('name'):
30773080
global_checkbutton_count
30783081
name=self.__class__.__name__.lower()
30793082
_checkbutton_count+=1
3080-
cnf['name']=f'!{name}{_checkbutton_count}'
3083+
# To avoid collisions with ttk.Checkbutton, use the different
3084+
# name template.
3085+
cnf['name']=f'!{name}-{_checkbutton_count}'
30813086
super()._setup(master,cnf)
30823087

30833088
defdeselect(self):

‎Lib/tkinter/test/test_ttk/test_widgets.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,29 @@ def test_unique_variables(self):
287287
b.pack()
288288
buttons.append(b)
289289
variables= [str(b['variable'])forbinbuttons]
290-
print(variables)
291290
self.assertEqual(len(set(variables)),4,variables)
292291

292+
deftest_unique_variables2(self):
293+
buttons= []
294+
f=ttk.Frame(self.root)
295+
f.pack()
296+
f=ttk.Frame(self.root)
297+
f.pack()
298+
forjin'AB':
299+
b=tkinter.Checkbutton(f,text=j)
300+
b.pack()
301+
buttons.append(b)
302+
# Should be larger than the number of all previously created
303+
# tkinter.Checkbutton widgets:
304+
forjinrange(100):
305+
b=ttk.Checkbutton(f,text=str(j))
306+
b.pack()
307+
buttons.append(b)
308+
names= [str(b)forbinbuttons]
309+
self.assertEqual(len(set(names)),len(buttons),names)
310+
variables= [str(b['variable'])forbinbuttons]
311+
self.assertEqual(len(set(variables)),len(buttons),variables)
312+
293313

294314
@add_standard_options(IntegerSizeTests,StandardTtkOptionsTests)
295315
classEntryTest(AbstractWidgetTest,unittest.TestCase):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Change automatically generated:class:`tkinter.Checkbutton` widget names to
2+
avoid collisions with automatically generated
3+
:class:`tkinter.ttk.Checkbutton` widget names within the same parent widget.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp