Tkinter: How to "break" class-event-bindings from within tag-bindings?

Jeff Epler jepler at
Mon Sep 9 15:57:30 CEST 2002

On Mon, Sep 09, 2002 at 03:01:16PM +0200, Michael Schwarz wrote:
> A "break" as the return value of a tag-event-binding for the 
> Text-widget seems not to prevent the standard event-handling of the 
> widget to occur.

I can reproduce this in a bare "wish" script, without involving Python.
I tested on wish8.4 (somewhat stale CVS) and 8.3.3.

The manpage for text(n) says this:
     It is possible for the current character  to have  multiple tags,
     and for each of them to have  a  binding  for  a  particular
     event sequence.   When this occurs, one binding is invoked for
     each tag, in order from  lowest- priority  to highest priority.
     If there are multiple matching bindings for a single tag, then  the
     most  specific  binding is chosen (see the manual entry for the
     bind  command for  details).   continue and break commands within
     binding scripts are processed in  the same  way  as  for bindings
     created with the bind command.

     If bindings are created for the widget as  a whole  using  the  bind
     command, then those bindings will supplement the  tag  bindings.
     The tag bindings will be invoked first, followed by bindings for
     the window as a whole.
I'm not sure if this is the intended behavior or not.  After all,
continue and break are supposed to be processed 'in the same way as'
normal bindings. However, maybe the word "supplement" and the description
"followed by bindings for the window as a whole" are supposed to describe
the behavior you saw as correct.

You may wish to file a bug against tk or post in a tk newsgroup
(comp.lang.tcl) to ask whether this behavior is correct or is a bug.

My "wish" script to show the problem:

text .t
.t insert end "Link\n\nJump HERE"
.t tag add link 1.0 1.4
.t tag bind link <1> { jump; break }
.t tag config link -underline on -foreground blue

#bind .t <1> { break }

proc jump {} {
    .t tag remove sel 0.0 end
    .t tag add sel 3.5 3.9

pack .t

More information about the Python-list mailing list