Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Lib/lib-tk/test/test_ttk/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,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)

Expand Down
3 changes: 2 additions & 1 deletion Lib/lib-tk/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,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)
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ James Rutherford
Chris Ryland
Constantina S.
Matthieu S
Cheryl Sabella
Patrick Sabin
Sébastien Sablé
Suman Saha
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Change ``ttk.OptionMenu`` radiobuttons to be unique across instances of
``OptionMenu``.