Tkinter <<Modified>> and bindtags ordering

bytecolor bytecolor at yahoo.com
Tue Apr 3 06:00:41 CEST 2007


I'm trying to extract the text of the current line on the <<Modified>>
event.
It doesnt work if I delete a character. If I type 'abc' I get 'abc' in
text_changed().
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
    t.tk.call(t._w, 'edit', 'modified', 0)
    changing = False

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

--
bytecolor




More information about the Python-list mailing list