Tkinter <<Modified>> and bindtags ordering

bytecolor bytecolor at
Tue Apr 3 06:00:41 CEST 2007

I'm trying to extract the text of the current line on the <<Modified>>
It doesnt work if I delete a character. If I type 'abc' I get 'abc' in
If I hit backspace I still get 'abc'. Backspace once more, I get 'ab'.
So the
callback is called before the text is changed. But only on a delete.
Someone told me it has to do with bindtags ordering. I've read what
docs I can
find on the subject, but I cant figure out why it's not working. Maybe
I should
learn a bit of Tcl, eh?

import Tkinter as tk

def text_changed(evt):
    global changing
    if changing: return
    changing = True
    line, col = t.index('insert').split('.')
    txt = t.get('%s.0' % line, '%s.end' % line)
    print '|%s|' % txt, 'edit', 'modified', 0)
    changing = False

changing = False
root = tk.Tk()
t = tk.Text(master=root)
t.focus_set(), 'edit', 'modified', 0)
t.bind('<<Modified>>', text_changed)


More information about the Python-list mailing list