On Thu, 11 Oct 2012 12:39:35 -0500 Bryan Oakley <bryan.oak...@gmail.com> wrote:
> That's more complicated than it needs to be. I'll give you the same > advice as I just gave someone else: are you aware of "bind_all" and > Tkinter's bindtags? That is a much cleaner way to implement global > bindings IMO. The advantage to "bind_all" is that individual widgets > can override the default bindings if they want (eg: if you want > control-o to mean something totally different only in one widget, you > can). It is not certain if we are talking about global bindings however, that depends on the the OP's application. In the case of my example the bindings just apply to the widgets inside one particular container, not globally to all widgets. Then it comes in handy to simply do: for widget in (button1, button2, button3, entry1, spinbox1, spinbox2): apply_default_bindings(widget) That's just three extra lines including the function definition to apply quite a bunch of bindings to all relevant widgets, I don't think this is so awfully complicated ;) There is of course bind_all, as well as bind_class and bindtags or the simple possibility of a custom widget class with extra default bindings. Which one is the best of course depends on what exactly you want to achieve and how the application window is designed. I think global bindings are usually fine for simple window layouts, but for more complex apps with several windows or several containers in one window (e.g. in Tab-like interfaces), custom dialogs etc. you may have to be careful to avoid unwanted effects. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "Life and death are seldom logical." "But attaining a desired goal always is." -- McCoy and Spock, "The Galileo Seven", stardate 2821.7 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss