How Can I Update Entry Without A "submit" Button In Tkinter?
Solution 1:
You can use either
FocusOut
tab
orenter
KeyKeyRelease
bindings to achieve that.
Also validation functions can help as they have previous and new values available. Please read the docs for more information on that matter.
It is IMHO the most "pythonic" / "tkinter" way of achieving what is a "check and submit" functionality.
Edit
As stated by OP, binding focusout
could lead to problems here an example how it does indeed work:
import Tkinter as tk
import sys
def focus_out_event(event):
print >> sys.stderr, "Focus-Out event called with args: %s"%event
print >> sys.stderr, "Entry Widget Content: %s"%event.widget.get()
def key_release_event(event):
print >> sys.stderr, "Key-Release event called with args: %s"%event
print >> sys.stderr, "Entry Widget Content: %s"%event.widget.get()
if __name__ == "__main__":
root = tk.Tk()
entry1 = tk.Entry(root)
entry1.bind("", key_release_event)
entry1.bind("", focus_out_event)
entry1.grid()
entry2 = tk.Entry(root)
entry2.bind("", key_release_event)
entry2.bind("", focus_out_event)
entry2.grid()
root.mainloop()
Test: - enter text ("asd") to entry1 - click into entry2
The last line of output is from changing to screenshot (event that fired a focusout
)
Solution 2:
You have this key-press
in event.char
so you can add it to text.
Solution 3:
I decided that <Key>
was not the right option in my case and instead used <FocusOut>
. This way, if you either change the value using the mouse or keyboard TAB
, on focus out it will update it.
Post a Comment for "How Can I Update Entry Without A "submit" Button In Tkinter?"