On Thu, Oct 11, 2012 at 11:20 AM,  <mkieve...@tlink.de> wrote:
> Sorry, to have been unclear here.
> My main interest is capturing all keyboard input
> with these lines:
> ------------------------------
>
> def on_key(event):
>     print('key')
>
> f.bind('<Key>', on_key)

There are better ways to capture all keyboard input if that's your
real goal. Are you aware of the "bind_all" method, which associates a
binding with all widgets? Typically this is used for shortcuts, but it
can be used any time you want to capture certain events no matter
where they occur.

Tkinter has the notion of "bind tags" (or bindtags). To this day, no
other GUI toolkit has as powerful of a mechanism for managing events;
this is truly one of Tkinter's hidden gems. The short version is, you
can associate a custom tag to any (or every) widget, and then bind to
that tag. Then, no matter what widget has focus, your binding will
fire. The advantage this has over "bind_all" is that with the bindtag
you can control when the event is processed -- before the actual
event, after the actual event, etc. With "bind_all", the "all"
bindings by default are processed after event and class level
bindings. The practical implication of that is that the widget or
class bindings have the option to prevent the event from propagating.
With bind tags you can guarantee your bindings fire before any others.



I
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to