Exactly as the question says. Text
widgets have the <<Modified>>
event, but Entry
widgets don't appear to.
In Tkinter, some widgets allow you to associate a callback function with an event using the command binding. It means that you can assign the name of a function to the command option of the widget so that when the event occurs on the widget, the function will be called automatically.
Sometimes, we need to change or modify the focus of any widget in the application which can be achieved by using the focus_set() method. This method sets the default focus for any widget and makes it active till the execution of the program.
An Entry widget in Tkinter is nothing but an input widget that accepts single-line user input in a text field. To return the data entered in an Entry widget, we have to use the get() method. It returns the data of the entry widget which further can be printed on the console.
Methods: The various methods provided by the entry widget are: get() : Returns the entry's current text as a string. delete() : Deletes characters from the widget. insert ( index, 'name') : Inserts string 'name' before the character at the given index.
Add a Tkinter StringVar to your Entry widget. Bind your callback to the StringVar using the trace method.
from Tkinter import * def callback(sv): print sv.get() root = Tk() sv = StringVar() sv.trace("w", lambda name, index, mode, sv=sv: callback(sv)) e = Entry(root, textvariable=sv) e.pack() root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With