diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-09-27 11:05:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-27 11:05:05 (GMT) |
commit | adbed2d542a815b8175db965742211856b19b52f (patch) | |
tree | 02836d64eb0d9bf35c5519a8a69f11fb0e408dbf /Lib/test/test_tkinter/test_widgets.py | |
parent | 68c46ae68b6e0c36a12e37285fff9ce0782ed01e (diff) | |
download | cpython-adbed2d542a815b8175db965742211856b19b52f.zip cpython-adbed2d542a815b8175db965742211856b19b52f.tar.gz cpython-adbed2d542a815b8175db965742211856b19b52f.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/test_tkinter/test_widgets.py')
-rw-r--r-- | Lib/test/test_tkinter/test_widgets.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_tkinter/test_widgets.py b/Lib/test/test_tkinter/test_widgets.py index 1cddbe1..6cde1cc 100644 --- a/Lib/test/test_tkinter/test_widgets.py +++ b/Lib/test/test_tkinter/test_widgets.py @@ -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): |