summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCheryl Sabella <cheryl.sabella@gmail.com>2017-09-10 06:02:14 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-09-10 06:02:14 (GMT)
commite1847ea4a9bdc7549893091a63e14f2afbdecc32 (patch)
tree0ea4debd045babcd281289f03d18df682e791c37 /Lib
parentae16b9966da1ac083796ecbffff004e3060b7731 (diff)
downloadcpython-e1847ea4a9bdc7549893091a63e14f2afbdecc32.zip
cpython-e1847ea4a9bdc7549893091a63e14f2afbdecc32.tar.gz
cpython-e1847ea4a9bdc7549893091a63e14f2afbdecc32.tar.bz2
bpo-25684: ttk.OptionMenu radiobuttons weren't unique (GH-2276) (GH-2960)
ttk.OptionMenu radiobuttons weren't unique between instances of OptionMenu. (cherry picked from commit a568e5273382a5dca0c27274f7d8e34c41a87d4d)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/lib-tk/test/test_ttk/test_extensions.py25
-rw-r--r--Lib/lib-tk/ttk.py3
2 files changed, 27 insertions, 1 deletions
diff --git a/Lib/lib-tk/test/test_ttk/test_extensions.py b/Lib/lib-tk/test/test_ttk/test_extensions.py
index 57ffddd..70b2f9c 100644
--- a/Lib/lib-tk/test/test_ttk/test_extensions.py
+++ b/Lib/lib-tk/test/test_ttk/test_extensions.py
@@ -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)
diff --git a/Lib/lib-tk/ttk.py b/Lib/lib-tk/ttk.py
index 77c93b1..6da1eb1 100644
--- a/Lib/lib-tk/ttk.py
+++ b/Lib/lib-tk/ttk.py
@@ -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)