Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25091
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Tkinter.event.widget: handler gets name instead of widget. |
| Date | 2012-07-09 15:45 -0400 |
| References | <1341782353.2041.136.camel@hatchbox-one> <mailman.1933.1341813557.4697.python-list@python.org> <e903a18d-a348-4ba3-8b0c-2b51bca7dbd6@l32g2000yqc.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1953.1341863177.4697.python-list@python.org> (permalink) |
On 7/9/2012 1:49 PM, Rick Johnson wrote:
> On Jul 9, 12:58 am, Terry Reedy <tjre...@udel.edu> wrote:
>> When posting problem code, you should post a minimal, self-contained
>> example that people can try on other systems and versions. Can you
>> create the problem with one record, which you could give, and one
>> binding? Do you need 4 fields, or would 1 'work'?
>
> I'll firmly back that sentiment. Fredric, if you cannot get the
> following simple code events to work properly, then how do you think
> you can get events working properly on something more complex?
>
> ## START CODE ARTISTRY ##
> import Tkinter as tk
> from Tkconstants import *
>
> class MyFrame(tk.Frame):
> def __init__(self, master, **kw):
> tk.Frame.__init__(self, master, **kw)
> self.bind('<Enter>', self.evtMouseEnter)
> self.bind('<Leave>', self.evtMouseLeave)
> self.bind('<Button-1>', self.evtButtonOneClick)
>
> def evtMouseEnter(self, event):
> event.widget.config(bg='magenta')
>
> def evtMouseLeave(self, event):
> event.widget.config(bg='SystemButtonFace')
>
> def evtButtonOneClick(self, event):
> event.widget.config(bg='green')
>
> if __name__ == '__main__':
> root = tk.Tk()
> for x in range(10):
> f = MyFrame(root, height=20, bd=1, relief=SOLID)
> f.pack(fill=X, expand=YES, padx=5, pady=5)
> root.mainloop()
> ## END CODE ARTISTRY ##
I copied and pasted this self-contained code into a 3.3 Idle edit window
and lightly edited for 3.x. Change 'Tkinter' to 'tkinter', remove
tkconstants import and prefix constants with 'tk.'. (The alternative:
change 'tkconstants' to 'tkinter.constants', but I prefer prefixes). It
runs as expected.
import tkinter as tk
class MyFrame(tk.Frame):
def __init__(self, master, **kw):
tk.Frame.__init__(self, master, **kw)
self.bind('<Enter>', self.evtMouseEnter)
self.bind('<Leave>', self.evtMouseLeave)
self.bind('<Button-1>', self.evtButtonOneClick)
def evtMouseEnter(self, event):
event.widget.config(bg='magenta')
def evtMouseLeave(self, event):
event.widget.config(bg='SystemButtonFace')
def evtButtonOneClick(self, event):
event.widget.config(bg='green')
if __name__ == '__main__':
root = tk.Tk()
for x in range(10):
f = MyFrame(root, height=20, bd=1, relief=tk.SOLID)
f.pack(fill=tk.X, expand=tk.YES, padx=5, pady=5)
root.mainloop()
Add details and data (maybe less than 10 records) until you get what you
want or recreate problem.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Tkinter.event.widget: handler gets name instead of widget. Terry Reedy <tjreedy@udel.edu> - 2012-07-09 01:58 -0400
Re: Tkinter.event.widget: handler gets name instead of widget. Rick Johnson <rantingrickjohnson@gmail.com> - 2012-07-09 10:49 -0700
Re: Tkinter.event.widget: handler gets name instead of widget. Terry Reedy <tjreedy@udel.edu> - 2012-07-09 15:45 -0400
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-09 22:47 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. Chris Angelico <rosuav@gmail.com> - 2012-07-10 08:23 +1000
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-10 12:03 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. Rick Johnson <rantingrickjohnson@gmail.com> - 2012-07-10 15:11 -0700
Re: Tkinter.event.widget: handler gets name instead of widget. Rick Johnson <rantingrickjohnson@gmail.com> - 2012-07-10 18:06 -0700
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-11 09:59 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-12 20:53 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. rantingrickjohnson@gmail.com - 2012-07-14 20:10 -0700
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-16 12:32 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. rantingrickjohnson@gmail.com - 2012-07-14 20:10 -0700
Re: Tkinter.event.widget: handler gets name instead of widget. Peter Otten <__peter__@web.de> - 2012-07-13 09:26 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-13 22:24 +0200
Re: Tkinter.event.widget: handler gets name instead of widget. Terry Reedy <tjreedy@udel.edu> - 2012-07-13 19:23 -0400
Re: Tkinter.event.widget: handler gets name instead of widget. Peter Otten <__peter__@web.de> - 2012-07-14 09:47 +0200
csiph-web