]> granicus.if.org Git - python/commitdiff
bpo-25684: ttk.OptionMenu radiobuttons weren't unique (GH-2276) (GH-2960)
authorCheryl Sabella <cheryl.sabella@gmail.com>
Sun, 10 Sep 2017 06:02:14 +0000 (02:02 -0400)
committerMariatta <Mariatta@users.noreply.github.com>
Sun, 10 Sep 2017 06:02:14 +0000 (23:02 -0700)
ttk.OptionMenu radiobuttons weren't unique
between instances of OptionMenu.
(cherry picked from commit a568e5273382a5dca0c27274f7d8e34c41a87d4d)

Lib/lib-tk/test/test_ttk/test_extensions.py
Lib/lib-tk/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 57ffdddb7d8119fdc146b1bd73175ee0cb009bbf..70b2f9c6b12461fca815337c1e87623b29a69b0b 100644 (file)
@@ -284,6 +284,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 77c93b12ae753b461375bcd379daed6c71e58909..6da1eb189f12aa86ef2423d07f4dffef23cc9016 100644 (file)
@@ -1614,7 +1614,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 229a874ffc2bcbd36785609c35e4bce20af2a8ad..688cd470d20436452d969c3cefd3fdac38d8d44b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1229,6 +1229,7 @@ James Rutherford
 Chris Ryland
 Constantina S.
 Matthieu S
+Cheryl Sabella
 Patrick Sabin
 SĂ©bastien SablĂ©
 Suman 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``.