I\'m proposing a continuation of the discussion in disable tkinter keyboard shortcut: I have an event handler for an event that Tkinter also uses, so that my prog & Tkinter
Bindings are handled in a specific order, defined by the bindtags
of that widget. By default this order is:
If there are conflicting bindings -- for example, a control-b binding on both the widget and class -- they both will fire (in the described order) unless you break the chain by returning "break"
.
In the case of the code you posted, however, you are binding to the toplevel window (ie: the root window), and the conflicting binding is on the class. Therefore, the binding will fire for the class before it is processed by the toplevel, so even if your binding returned "break"
it wouldn't matter since the class binding happens first.
The most straight-forward solution is to move your binding to the actual widget and return "break"
. That will guarantee your binding fires first, and the return "break"
guarantees that the class binding does not fire.
If you really want your binding on the root window, you can remove the binding for the class using the bind_class
method with the value of "Text"
for the class.
You might find the Events and Bindings page on effbot.org to be useful.