Tkinter Text widget's equivalent of Swing's DocumentEvent?

David Rushby woodsplitter at rocketmail.com
Thu Oct 5 13:23:45 EDT 2000


I'm trying to figure out the best way to process document change events in a
Tkinter Text widget.  In this case, I only care about textual changes, not
those related to embedded objects.

In Java's Swing, I'd use javax.Swing.Document.addDocumentListener to
register to receive a javax.swing.event.DocumentEvent every time the view's
underlying document changes.  I've done quite a bit of searching for a
Tkinter equivalent without success.  Suggestions that I consider grossly
inelegant are:

- Register event handlers for all keypresses and mouse actions that might
cause the document to change.  This method breaks if the user rebinds some
previously neutral key combo to change the document.

- Store an md5 digest of the widget's previous contents and compare it to an
md5 digest of the current contents to determine if a given keypress caused a
change.  The problem with this is that simply knowing that there has been a
change doesn't tell me the specifics of the change; expensive computation
would probably be necessary to determine those specifics.

Both of the above methods also require that the text widget's insert and
delete methods be overridden to detect programmatic changes.

I hope I'm ignoring something obvious.  Advice appreciated.





More information about the Python-list mailing list