bpo-45160: Ttk optionmenu only set variable once (GH-28291)

This commit is contained in:
E-Paine 2021-10-21 21:25:52 +01:00 committed by GitHub
parent 0c4c2e6213
commit add46f8476
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -301,6 +301,19 @@ class OptionMenuTest(AbstractTkTest, unittest.TestCase):
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):