combobox - python ttk : How to detect if at least one of the widgets of a frame is updated by the user? -
i have frame contains multiple entry , combobox widgets. widgets filled default values when frame populated.
i wondering if there simple way detect entry/combobox widgets have been updated user.
if not, require me go through entry/combobox widgets 1 one , store new value if different default one.
if able save time copying values of items have changed without need compare them first.
i not sure understand trying achieve, 2 options can think
- iterate through each widget , compare reference values (the 1 evoke in question)
- bind edits on widgets , either store new values, or handle list of edited widgets
the usual way perform former in gui through binding , callbacks. if use entry
, ttk.combobox
, can handle both stringvar
, trace
bindings.
here snippet (inspired this answer) illustrating callback aware of edited widget. handle damage list (with widgets have been edited) or data structure modified value.
from tkinter import * import ttk def callback(name, sv): print "{0}: {1}".format(name, sv.get()) root = tk() sv = stringvar() sv.trace("w", lambda name, index, mode, sv=sv: callback("one", sv)) e = entry(root, textvariable=sv) e.pack() sv = stringvar() sv.trace("w", lambda name, index, mode, sv=sv: callback("two", sv)) e = entry(root, textvariable=sv) e.pack() sv = stringvar() box = ttk.combobox(root, textvariable=sv) box.pack() box['values'] = ('x', 'y', 'z') box.current(0) sv.trace("w", lambda name, index, mode, sv=sv: callback("three", sv)) root.mainloop()
Comments
Post a Comment