Reputation: 213
I have been studying validatecommand patterns like in this post:
Interactively validating Entry widget content in tkinter
My question is that one of the actions on an entry widget that triggers the callback is 'focusin'.
I would like to use this to clear the contents of the entry, however, the entry object does not appear to be not passed to the callback.
Am I approaching this the wrong way? Is there another way to wire the focusin event for an entry widget and still be able to execute validation?
Of course I could hard code entry.delete but I want it to work for any entry widget on the GUI.
def onValidate(self, d, i, P, s, S, v, V, W):
if self._is_number(S):
return True
else:
self.bell()
return False
def _add_widgets(self):
vcmd = (self.register(self.onValidate), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
self.f_entry = ttk.Entry(self.window, width=5, validate="all", textvariable=self.fahrenheit, validatecommand=vcmd).grid(row=1, column=2)
Upvotes: 0
Views: 108
Reputation: 385980
The validation feature should be used only for validation. If you want to delete when the widget gets focus you should set a binding on the <FocusIn>
event.
Upvotes: 1