Have you considered creating a subclass of entry? Then your code is simply:

    LEnt = CustomEntry(stuff stuff stuff)

You can then put all the bind magic in the constructor of CustomEntry.



On Sat, Jul 19, 2014 at 12:21 PM, Bob Greschke <b...@passcal.nmt.edu> wrote:

>
> On 2014-07-19, at 05:21, Michael Lange <klappn...@web.de> wrote:
>
> > Hi,
> >
> > On Fri, 18 Jul 2014 16:54:34 -0600
> > Bob Greschke <b...@passcal.nmt.edu> wrote:
> >
> >> I have a huge program...several huge programs...and I keep writing
> >> duplicate sets of calls for <Return> and <KP_enter>.  I'm tired of it,
> >> even though they are already all written.  Is there any way to combine
> >> those (those two, specifically) into one bind like
> >>
> >> x.bind(("<Return>", "<KP_Enter"), command = .....?
> >>
> >> I know you can't do that, but something like that on a global scale
> >> (both figuratively, and programmatically).  Some little line of code at
> >> the beginning of the program that redirects the <KP_Enter> to the
> >> <Return> event when some field or whatever is specifically looking for
> >> either return key to be pressed?.
> >
> > you could use event_generate() and bind_class(), as in this example:
> >
> > from Tkinter import *
> > root = Tk()
> >
> > def on_kp_enter(event):
> >    event.widget.event_generate('<Return>')
> > root.bind_class('Button', '<KP_Enter>', on_kp_enter)
> >
> > def on_return(event):
> >    print('Return')
> >
> > b = Button(root, text='Push me')
> > b.pack()
> > b.bind('<Return>', on_return)
> > root.mainloop()
> >
> > Regards
> >
> > Michael
> >
> > .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. .
> .-.
> >
> > Lots of people drink from the wrong bottle sometimes.
> >               -- Edith Keeler, "The City on the Edge of Forever",
> >                  stardate unknown
> > _______________________________________________
> > Tkinter-discuss mailing list
> > Tkinter-discuss@python.org
> > https://mail.python.org/mailman/listinfo/tkinter-discuss
>
> You are one smart guy!  This helps a lot.
>
> I can tolerate doing
>
> LEnt = Entry(stuff stuff stuff)
> LEnt.bind("<Return>", "call call call")
> LEnt.bind("<KP_Enter>", on_kp_enter)
>
> I can't really do the bind_class, because not all fields respond to a
> Return/Enter.
> What I'm trying to do is eliminate duplicating the "call call call" part
> like I have now.  Some/Most of the calls are kinda complex (a lot of
> argument passing to the handlers).  I'd seen that event_generate() a long
> time ago, but I never figured out how to use it from the Grayson Bible.
>  Now as I rescan that portion of the book I realize you may have made me
> dangerous. :)
>
> Thanks!
>
> Bob
>
>
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss@python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss
>
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to