FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-45160: Ttk optionmenu only set variable once by E-Paine · Pull Request #28291 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions Lib/tkinter/test/test_ttk/test_extensions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
5 changes: 4 additions & 1 deletion Lib/tkinter/ttk.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
Comment thread
E-Paine marked this conversation as resolved.
variable=self._variable)

if default:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When tracing a tkinter variable used by a ttk OptionMenu, callbacks are no longer made twice.

Back | FazBrowse Home | New Git URL