]> granicus.if.org Git - python/commitdiff
[3.6] bpo-25684: ttk.OptionMenu radiobuttons weren't unique (GH-2276) (#2959)
authorcsabella <cheryl.sabella@gmail.com>
Mon, 31 Jul 2017 19:10:13 +0000 (15:10 -0400)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 31 Jul 2017 19:10:13 +0000 (22:10 +0300)
between instances of OptionMenu.
(cherry picked from commit a568e5273382a5dca0c27274f7d8e34c41a87d4d)

* Update Misc/ACKS

Lib/tkinter/test/test_ttk/test_extensions.py
Lib/tkinter/ttk.py
Misc/ACKS
Misc/NEWS.d/next/Library/2017-07-17-11-35-00.bpo-25684.usELVx.rst [new file with mode: 0644]

index 218b27fc30ea1b8650ccd68338a17068702a0f34..a45f882bb00d48cc51e4d18921008f99856e798d 100644 (file)
@@ -291,6 +291,31 @@ class OptionMenuTest(AbstractTkTest, unittest.TestCase):
 
         optmenu.destroy()
 
+    def test_unique_radiobuttons(self):
+        # check that radiobuttons are unique across instances (bpo25684)
+        items = ('a', 'b', 'c')
+        default = 'a'
+        optmenu = ttk.OptionMenu(self.root, self.textvar, default, *items)
+        textvar2 = tkinter.StringVar(self.root)
+        optmenu2 = ttk.OptionMenu(self.root, textvar2, default, *items)
+        optmenu.pack()
+        optmenu.wait_visibility()
+        optmenu2.pack()
+        optmenu2.wait_visibility()
+        optmenu['menu'].invoke(1)
+        optmenu2['menu'].invoke(2)
+        optmenu_stringvar_name = optmenu['menu'].entrycget(0, 'variable')
+        optmenu2_stringvar_name = optmenu2['menu'].entrycget(0, 'variable')
+        self.assertNotEqual(optmenu_stringvar_name,
+                            optmenu2_stringvar_name)
+        self.assertEqual(self.root.tk.globalgetvar(optmenu_stringvar_name),
+                         items[1])
+        self.assertEqual(self.root.tk.globalgetvar(optmenu2_stringvar_name),
+                         items[2])
+
+        optmenu.destroy()
+        optmenu2.destroy()
+
 
 tests_gui = (LabeledScaleTest, OptionMenuTest)
 
index c474e60713f75e91902be5388dfd71436299915d..9cd0c2073a9f59b66f21ae82cfd9cfa840540101 100644 (file)
@@ -1638,7 +1638,8 @@ class OptionMenu(Menubutton):
         menu.delete(0, 'end')
         for val in values:
             menu.add_radiobutton(label=val,
-                command=tkinter._setit(self._variable, val, self._callback))
+                command=tkinter._setit(self._variable, val, self._callback),
+                variable=self._variable)
 
         if default:
             self._variable.set(default)
index b6b355b614b8208a175a71b806dd7062384e697c..7bc13ff0c9e55aed3d3aa966b6d1385bf0140384 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1340,6 +1340,7 @@ Chris Ryland
 Bernt Røskar Brenna
 Constantina S.
 Matthieu S
+Cheryl Sabella
 Patrick Sabin
 Sébastien Sablé
 Amit Saha
diff --git a/Misc/NEWS.d/next/Library/2017-07-17-11-35-00.bpo-25684.usELVx.rst b/Misc/NEWS.d/next/Library/2017-07-17-11-35-00.bpo-25684.usELVx.rst
new file mode 100644 (file)
index 0000000..61d6b29
--- /dev/null
@@ -0,0 +1,2 @@
+Change ``ttk.OptionMenu`` radiobuttons to be unique across instances of
+``OptionMenu``.