[3.6] bpo-25684: ttk.OptionMenu radiobuttons weren't unique (GH-2276) (#2959)

between instances of OptionMenu.
(cherry picked from commit a568e52733)

* Update Misc/ACKS
This commit is contained in:
csabella 2017-07-31 15:10:13 -04:00 committed by Serhiy Storchaka
parent 8c4e5be1df
commit 2bf1586e60
4 changed files with 30 additions and 1 deletions

View File

@ -291,6 +291,31 @@ class OptionMenuTest(AbstractTkTest, unittest.TestCase):
optmenu.destroy() 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) tests_gui = (LabeledScaleTest, OptionMenuTest)

View File

@ -1638,7 +1638,8 @@ class OptionMenu(Menubutton):
menu.delete(0, 'end') menu.delete(0, 'end')
for val in values: for val in values:
menu.add_radiobutton(label=val, 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: if default:
self._variable.set(default) self._variable.set(default)

View File

@ -1340,6 +1340,7 @@ Chris Ryland
Bernt Røskar Brenna Bernt Røskar Brenna
Constantina S. Constantina S.
Matthieu S Matthieu S
Cheryl Sabella
Patrick Sabin Patrick Sabin
Sébastien Sablé Sébastien Sablé
Amit Saha Amit Saha

View File

@ -0,0 +1,2 @@
Change ``ttk.OptionMenu`` radiobuttons to be unique across instances of
``OptionMenu``.