mirror of
https://github.com/python/cpython
synced 2024-09-05 16:38:56 +00:00
bpo-45160: Ttk optionmenu only set variable once (GH-28291)
This commit is contained in:
parent
0c4c2e6213
commit
add46f8476
|
@ -301,6 +301,19 @@ def test_unique_radiobuttons(self):
|
|||
optmenu.destroy()
|
||||
optmenu2.destroy()
|
||||
|
||||
def test_trace_variable(self):
|
||||
# prior to bpo45160, tracing a variable would cause the callback to be made twice
|
||||
success = []
|
||||
items = ('a', 'b', 'c')
|
||||
textvar = tkinter.StringVar(self.root)
|
||||
def cb_test(*args):
|
||||
self.assertEqual(textvar.get(), items[1])
|
||||
success.append(True)
|
||||
optmenu = ttk.OptionMenu(self.root, textvar, "a", *items)
|
||||
textvar.trace("w", cb_test)
|
||||
optmenu['menu'].invoke(1)
|
||||
self.assertEqual(success, [True])
|
||||
|
||||
|
||||
class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
|
||||
|
||||
|
|
|
@ -1643,7 +1643,10 @@ 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=(
|
||||
None if self._callback is None
|
||||
else lambda val=val: self._callback(val)
|
||||
),
|
||||
variable=self._variable)
|
||||
|
||||
if default:
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
When tracing a tkinter variable used by a ttk OptionMenu, callbacks are no longer made twice.
|
Loading…
Reference in a new issue