Tkinter default bindings

Phil Schmidt phil_nospam_schmidt at
Mon Mar 1 17:49:51 CET 2004

I have an Entry widget inside a Frame. The Frame contains other
widgets as well. I have bound the <Key> event to the Frame, but I
don't want the Frame to receive the event when the Entry widget has

So, I bound the <Key> event to the Entry widget (bound to method
a_key()). This works, except that both the Entry and Frame widgets get
the event. This also forces me to implement event handlers, which is
fine for the Frame since that's what I want to do. But I want the
Entry to use its default handler, not my own handler. Rather than
duplicate all that functionality, I found I could accomplish this by
temporarily unbinding the events, re-generating the event, and then
re-binding the events, as follows:

    def a_key(self, e):'<Key>')
        self.entry.bind('<Key>', self.a_key)'<Key>', self._parent_class__keypress)
        return 'break'

This works, but it's kludgy. Is there a better way to do this? I just
want the Entry widget to receive the event when it has focus, behave
in its default manner, and not have the event propagate upward to
containing widgets.

More information about the Python-list mailing list