From bob at passcal.nmt.edu Sat Jul 19 00:54:34 2014 From: bob at passcal.nmt.edu (Bob Greschke) Date: Fri, 18 Jul 2014 16:54:34 -0600 Subject: [Tkinter-discuss] Combining events? Message-ID: <6E1EAABE-64FC-4FD1-8901-10B4326C2DAF@passcal.nmt.edu> I have a huge program...several huge programs...and I keep writing duplicate sets of calls for and . 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(("", " to the event when some field or whatever is specifically looking for either return key to be pressed?. Thanks! From klappnase at web.de Sat Jul 19 13:21:19 2014 From: klappnase at web.de (Michael Lange) Date: Sat, 19 Jul 2014 13:21:19 +0200 Subject: [Tkinter-discuss] Combining events? In-Reply-To: <6E1EAABE-64FC-4FD1-8901-10B4326C2DAF@passcal.nmt.edu> References: <6E1EAABE-64FC-4FD1-8901-10B4326C2DAF@passcal.nmt.edu> Message-ID: <20140719132119.eaad93f59e46d8708bba1b72@web.de> Hi, On Fri, 18 Jul 2014 16:54:34 -0600 Bob Greschke wrote: > I have a huge program...several huge programs...and I keep writing > duplicate sets of calls for and . 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(("", " > 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 to the > 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('') root.bind_class('Button', '', on_kp_enter) def on_return(event): print('Return') b = Button(root, text='Push me') b.pack() b.bind('', 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 From bob at passcal.nmt.edu Sat Jul 19 19:21:00 2014 From: bob at passcal.nmt.edu (Bob Greschke) Date: Sat, 19 Jul 2014 11:21:00 -0600 Subject: [Tkinter-discuss] Combining events? In-Reply-To: <20140719132119.eaad93f59e46d8708bba1b72@web.de> References: <6E1EAABE-64FC-4FD1-8901-10B4326C2DAF@passcal.nmt.edu> <20140719132119.eaad93f59e46d8708bba1b72@web.de> Message-ID: <48AAAD84-185D-4E7D-8D40-EF800D9934BF@passcal.nmt.edu> On 2014-07-19, at 05:21, Michael Lange wrote: > Hi, > > On Fri, 18 Jul 2014 16:54:34 -0600 > Bob Greschke wrote: > >> I have a huge program...several huge programs...and I keep writing >> duplicate sets of calls for and . 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(("", "> >> 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 to the >> 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('') > root.bind_class('Button', '', on_kp_enter) > > def on_return(event): > print('Return') > > b = Button(root, text='Push me') > b.pack() > b.bind('', 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 at 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("", "call call call") LEnt.bind("", 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 From bryan.oakley at gmail.com Sat Jul 19 19:37:36 2014 From: bryan.oakley at gmail.com (Bryan Oakley) Date: Sat, 19 Jul 2014 12:37:36 -0500 Subject: [Tkinter-discuss] Combining events? In-Reply-To: <48AAAD84-185D-4E7D-8D40-EF800D9934BF@passcal.nmt.edu> References: <6E1EAABE-64FC-4FD1-8901-10B4326C2DAF@passcal.nmt.edu> <20140719132119.eaad93f59e46d8708bba1b72@web.de> <48AAAD84-185D-4E7D-8D40-EF800D9934BF@passcal.nmt.edu> Message-ID: 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 wrote: > > On 2014-07-19, at 05:21, Michael Lange wrote: > > > Hi, > > > > On Fri, 18 Jul 2014 16:54:34 -0600 > > Bob Greschke wrote: > > > >> I have a huge program...several huge programs...and I keep writing > >> duplicate sets of calls for and . 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(("", " >> > >> 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 to the > >> 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('') > > root.bind_class('Button', '', on_kp_enter) > > > > def on_return(event): > > print('Return') > > > > b = Button(root, text='Push me') > > b.pack() > > b.bind('', 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 at 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("", "call call call") > LEnt.bind("", 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 at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at passcal.nmt.edu Sat Jul 19 23:03:06 2014 From: bob at passcal.nmt.edu (Bob Greschke) Date: Sat, 19 Jul 2014 15:03:06 -0600 Subject: [Tkinter-discuss] Combining events? In-Reply-To: References: <6E1EAABE-64FC-4FD1-8901-10B4326C2DAF@passcal.nmt.edu> <20140719132119.eaad93f59e46d8708bba1b72@web.de> <48AAAD84-185D-4E7D-8D40-EF800D9934BF@passcal.nmt.edu> Message-ID: On 2014-07-19, at 11:37, Bryan Oakley wrote: > 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. All of the Entry() field setups are different. Some of the ones I'm dealing with are simple: LEnt = Entry(Sub, textvariable = ADEInputVar, width = 25) LEnt.pack(side = LEFT) LEnt.bind("", formADFind) LEnt.bind("", formADFind) And some aren't: LEnt = Entry(Sub, textvariable = INLInputVar, width = 25) LEnt.bind("", Command(formINPickSelectPC, VarSet, "INPK", FindResults, \ eval("%sInPhylumVar"%VarSet), eval("%sInClassVar"%VarSet))) LEnt.bind("", Command(formINPickSelectPC, VarSet, "INPK", FindResults, \ eval("%sInPhylumVar"%VarSet), eval("%sInClassVar"%VarSet))) I'd still need to be passing a bunch of different stuff to the class for each field, so in my case it wouldn't buy me much, or save me too much typing to make a class. They aren't all doing the same thing. Here are some screenshots of the program that I'm working on. Any of the field labels that have an equals sign in them like "Description:=" are fields where the user can enter something and hit the Return key to perform and action. There are tooltips all over the real thing that tell them what a return will do. www.passcal.nmt.edu/~bob/passcal/software/pis.html Bob > > > > On Sat, Jul 19, 2014 at 12:21 PM, Bob Greschke wrote: > > On 2014-07-19, at 05:21, Michael Lange wrote: > > > Hi, > > > > On Fri, 18 Jul 2014 16:54:34 -0600 > > Bob Greschke wrote: > > > >> I have a huge program...several huge programs...and I keep writing > >> duplicate sets of calls for and . 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(("", " >> > >> 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 to the > >> 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('') > > root.bind_class('Button', '', on_kp_enter) > > > > def on_return(event): > > print('Return') > > > > b = Button(root, text='Push me') > > b.pack() > > b.bind('', 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 at 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("", "call call call") > LEnt.bind("", 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 at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: