Getting contents of Text / Entry widgets

catlee at my-deja.com catlee at my-deja.com
Tue Jul 6 15:47:13 EDT 1999


Hi,

I'm writing a little utility that uses a Tkinter Text widget (and an
Entry widget).  I want to perform an action for every key that is
entered.  So I do something like:

def callback(event):
   print event.widget.get()

widget=Entry()
widget.bind("<Key>",callback)

The problem with this is that the output generated by callback is
always one character behind.  I assume this is because when the event
is generated, the character you've typed hasn't been entered into the
buffer yet.  I could modify callback to look something like:
def callback(event):
   print event.widget.get() + event.char

But this doesn't handle backspace and delete characters well.

Is there a nice way of retrieving the contents of a Text / Entry widget
every time the widget's text buffer is changed (as opposed to whenever
a key is pressed)?

Thanks,
Chris


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list