From 49b9f65363459f9b5fcda94fc675bf99029e6735 Mon Sep 17 00:00:00 2001 From: csabella Date: Mon, 31 Jul 2017 05:30:09 -0400 Subject: [PATCH 1/2] bpo-25684: ttk.OptionMenu radiobuttons weren't unique (#2276) between instances of OptionMenu. (cherry picked from commit a568e5273382a5dca0c27274f7d8e34c41a87d4d) --- Lib/lib-tk/test/test_ttk/test_extensions.py | 25 +++++++++++++++++++ Lib/lib-tk/ttk.py | 3 ++- .../2017-07-17-11-35-00.bpo-25684.usELVx.rst | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2017-07-17-11-35-00.bpo-25684.usELVx.rst diff --git a/Lib/lib-tk/test/test_ttk/test_extensions.py b/Lib/lib-tk/test/test_ttk/test_extensions.py index 57ffdddb7d8119..70b2f9c6b12461 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 @@ 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/lib-tk/ttk.py b/Lib/lib-tk/ttk.py index 11254391c0f5f2..b36fa9469166d3 100644 --- a/Lib/lib-tk/ttk.py +++ b/Lib/lib-tk/ttk.py @@ -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) 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 00000000000000..61d6b29cafc3ec --- /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``. From fed996b7e5011598c71446747cda544d3f387a8a Mon Sep 17 00:00:00 2001 From: csabella Date: Mon, 31 Jul 2017 18:45:54 -0400 Subject: [PATCH 2/2] Update Misc/ACKS --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index 662db9f40f7826..08a7c295d40dfa 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1228,6 +1228,7 @@ James Rutherford Chris Ryland Constantina S. Matthieu S +Cheryl Sabella Patrick Sabin Sébastien Sablé Suman Saha