The Text Widget
Edward K. Ream
edream at tds.net
Mon Mar 4 04:26:18 EST 2002
Eric Brunel wrote:
> > First, note that if you bind to a key-press (<Key>) event, when the
> > event handler is called the Text widget hasn't been changed yet(!)
> > Other frameworks provide a "text will change" event and a "text did
> > change" event, but AFAIK Tk does not.
>
> Tk does: it's simply that the event "<Key>" is a short-cut for
> "<KeyPress>", called when the key is depressed, so before the insertion
> happened. To do a binding after the text has been inserted, the event is
> "<KeyRelease>".
Are you sure? I know I tried binding to <KeyRelease> and IIRC the text
had not changed. Or maybe my memory is faulty and there were some other
problems with <KeyRelease>. I do know that I tried and failed to find a
way to get an event "just after" the the text had changed instead of
waiting for idle time. I wanted to do this to make syntax coloring as
fast as possible. Note that my main testing was done on Windows, if that
makes any difference.
BTW, I had all kinds of problems distinguishing "plain" key-presses from
alt and control keys. I tried various ways of binding to <KeyPress> and
<KeyRelease> for the alt and control keys, without real success. I
finally gave up and just had my <Key> handlers check to see whether the
key-presses actually changed the text.
If you have an example of fancy bindings for Text widgets I'd love to
see it. Thanks.
Edward
--------------------------------------------------------------------
Edward K. Ream email: edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------
More information about the Python-list
mailing list