| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -301,6 +301,19 @@ def test_unique_radiobuttons(self): | |||
| 301 | 301 | optmenu.destroy() | |
| 302 | 302 | optmenu2.destroy() | |
| 303 | 303 | ||
| 304 | + def test_trace_variable(self): | ||
| 305 | + # prior to bpo45160, tracing a variable would cause the callback to be made twice | ||
| 306 | + success = [] | ||
| 307 | + items = ('a', 'b', 'c') | ||
| 308 | + textvar = tkinter.StringVar(self.root) | ||
| 309 | + def cb_test(*args): | ||
| 310 | + self.assertEqual(textvar.get(), items[1]) | ||
| 311 | + success.append(True) | ||
| 312 | + optmenu = ttk.OptionMenu(self.root, textvar, "a", *items) | ||
| 313 | + textvar.trace("w", cb_test) | ||
| 314 | + optmenu['menu'].invoke(1) | ||
| 315 | + self.assertEqual(success, [True]) | ||
| 316 | + | ||
| 304 | 317 | ||
| 305 | 318 | class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): | |
| 306 | 319 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1643,7 +1643,10 @@ def set_menu(self, default=None, *values): | |||
| 1643 | 1643 | menu.delete(0, 'end') | |
| 1644 | 1644 | for val in values: | |
| 1645 | 1645 | menu.add_radiobutton(label=val, | |
| 1646 | - command=tkinter._setit(self._variable, val, self._callback), | ||
| 1646 | + command=( | ||
| 1647 | + None if self._callback is None | ||
| 1648 | + else lambda val=val: self._callback(val) | ||
| 1649 | + ), | ||
| 1647 | 1650 | variable=self._variable) | |
| 1648 | 1651 | ||
| 1649 | 1652 | if default: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + When tracing a tkinter variable used by a ttk OptionMenu, callbacks are no longer made twice. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments