[Python-checkins] bpo-25684: ttk.OptionMenu radiobuttons weren't unique (#2276)

Serhiy Storchaka webhook-mailer at python.org
Mon Jul 31 05:30:12 EDT 2017


https://github.com/python/cpython/commit/a568e5273382a5dca0c27274f7d8e34c41a87d4d
commit: a568e5273382a5dca0c27274f7d8e34c41a87d4d
branch: master
author: csabella <cheryl.sabella at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017-07-31T12:30:09+03:00
summary:

bpo-25684: ttk.OptionMenu radiobuttons weren't unique (#2276)

between instances of OptionMenu.

files:
A Misc/NEWS.d/next/Library/2017-07-17-11-35-00.bpo-25684.usELVx.rst
M Lib/tkinter/test/test_ttk/test_extensions.py
M Lib/tkinter/ttk.py

diff --git a/Lib/tkinter/test/test_ttk/test_extensions.py b/Lib/tkinter/test/test_ttk/test_extensions.py
index 218b27fc30e..a45f882bb00 100644
--- a/Lib/tkinter/test/test_ttk/test_extensions.py
+++ b/Lib/tkinter/test/test_ttk/test_extensions.py
@@ -291,6 +291,31 @@ def cb_test(item):
 
         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)
 
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py
index cbaad76e008..3ecc004f0e0 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -1635,7 +1635,8 @@ def set_menu(self, default=None, *values):
         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)
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
index 00000000000..61d6b29cafc
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-07-17-11-35-00.bpo-25684.usELVx.rst
@@ -0,0 +1,2 @@
+Change ``ttk.OptionMenu`` radiobuttons to be unique across instances of
+``OptionMenu``.



More information about the Python-checkins mailing list