mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-73588: Fix generation of the default name of tkinter.Checkbutton. (GH-97547)
Previously, checkbuttons in different parent widgets could have the same short name and share the same state if arguments "name" and "variable" are not specified. Now they are globally unique.
This commit is contained in:
parent
68c46ae68b
commit
adbed2d542
6 changed files with 58 additions and 3 deletions
|
@ -212,6 +212,32 @@ class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
|
|||
widget = self.create()
|
||||
self.checkParams(widget, 'onvalue', 1, 2.3, '', 'any string')
|
||||
|
||||
def test_unique_variables(self):
|
||||
frames = []
|
||||
buttons = []
|
||||
for i in range(2):
|
||||
f = tkinter.Frame(self.root)
|
||||
f.pack()
|
||||
frames.append(f)
|
||||
for j in 'AB':
|
||||
b = tkinter.Checkbutton(f, text=j)
|
||||
b.pack()
|
||||
buttons.append(b)
|
||||
variables = [str(b['variable']) for b in buttons]
|
||||
self.assertEqual(len(set(variables)), 4, variables)
|
||||
|
||||
def test_same_name(self):
|
||||
f1 = tkinter.Frame(self.root)
|
||||
f2 = tkinter.Frame(self.root)
|
||||
b1 = tkinter.Checkbutton(f1, name='test', text='Test1')
|
||||
b2 = tkinter.Checkbutton(f2, name='test', text='Test2')
|
||||
|
||||
v = tkinter.IntVar(self.root, name='test')
|
||||
b1.select()
|
||||
self.assertEqual(v.get(), 1)
|
||||
b2.deselect()
|
||||
self.assertEqual(v.get(), 0)
|
||||
|
||||
|
||||
@add_standard_options(StandardOptionsTests)
|
||||
class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue