Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'root': 0.04; '__name__': 0.07; 'prefix': 0.07; 'tkinter': 0.07; 'versions.': 0.07; 'x-mailer:evolution 2.28.3': 0.07; 'python': 0.09; '"if': 0.09; 'event):': 0.09; 'failed:': 0.09; 'handlers': 0.09; 'processing,': 0.09; 'suggestions.': 0.09; 'terry': 0.09; 'url:peps': 0.09; 'def': 0.10; '(the': 0.15; 'properly': 0.15; "'__main__':": 0.16; '10:49': 0.16; 'blindly': 0.16; 'fine.': 0.16; 'identifiers.': 0.16; 'jumps': 0.16; 'reason.': 0.16; 'received:195.186': 0.16; 'received:bluewin.ch': 0.16; 'record,': 0.16; 'reedy': 0.16; 'reproduce': 0.16; 'stripped': 0.16; 'superfluous': 0.16; 'url:pep-0008': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'url:dev': 0.17; 'code,': 0.18; 'import': 0.21; 'strip': 0.22; 'example': 0.23; 'header:In-Reply-To:1': 0.25; '[1]': 0.27; 'am,': 0.27; 'possibly': 0.27; 'reflect': 0.27; 'skip:e 30': 0.27; 'skip:e 40': 0.27; 'strongly': 0.27; 'post': 0.28; '-0700,': 0.29; 'consistency': 0.29; 'horizontal': 0.29; 'style.': 0.29; 'case,': 0.29; 'points': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'worked': 0.30; 'error': 0.30; 'code': 0.31; 'url:python': 0.32; 'johnson': 0.32; 'structure': 0.32; 'could': 0.32; 'problem': 0.33; 'to:addr :python-list': 0.33; 'skip:- 20': 0.34; 'posting': 0.35; 'similar': 0.35; 'something': 0.35; 'url:org': 0.36; "i'll": 0.36; 'should': 0.36; 'bad': 0.37; 'does': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'space': 0.39; 'application': 0.40; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'end': 0.40; 'think': 0.40; 'your': 0.60; 'interest': 0.62; 'back': 0.62; 'invest': 0.62; 'details': 0.63; 'more': 0.63; 'our': 0.65; 'decided': 0.65; 'jul': 0.65; 'received:ch': 0.69; 'designers': 0.75; 'fields,': 0.84; 'idiotic': 0.84; 'subject:gets': 0.84; 'apparent': 0.91; 'rick': 0.91 Subject: Re: Tkinter.event.widget: handler gets name instead of widget. From: Frederic Rentsch To: python-list@python.org In-Reply-To: References: <1341782353.2041.136.camel@hatchbox-one> Content-Type: text/plain; charset="UTF-8" Date: Tue, 10 Jul 2012 12:03:34 +0200 Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341914690 news.xs4all.nl 6887 [2001:888:2000:d::a6]:59869 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25131 On Mon, 2012-07-09 at 10:49 -0700, Rick Johnson wrote: > On Jul 9, 12:58 am, Terry Reedy 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('', self.evtMouseEnter) > self.bind('', self.evtMouseLeave) > self.bind('', 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 ## > This works perfectly well! What makes the case difficult is an exceptional misbehavior for no apparent reason. If I manage to strip the critical section of environmental details in the interest of concision and legibility and still reproduce the error I shall post it. So far I have failed: the stripped model I distilled yesterday worked fine. > ----------------------- > More points to ponder: > ----------------------- > 1. Just because the Tkinter designers decided to use idiotic names for > event sequences does not mean you are required to blindly follow their > bad example (the whole: "if johnny jumps off a cliff...", thing comes > to mind) > > 2. I would strongly recommend you invest more thought into your event > handler identifiers. ALL event handlers should marked as *event > handlers* using a prefix. I like to use the prefix "evt". Some people > prefer other prefixes. In any case, just remember to be consistent. > Also, event handler names should reflect WHAT event they are > processing, not some esoteric functionality of the application like > "pick_record" or "info_profile". However if you like, simply have the > event handler CALL an outside func/meth. This type of consistency is > what separates the men from the boys. > > 3. The Python Style Guide[1] frowns on superfluous white space (be it > horizontal OR vertical!) I would strongly recommend you read and adapt > as much of this style as you possibly can bear. Even if we don't all > get along, it IS *very* important that we structure our code in a > similar style. > > [1] http://www.python.org/dev/peps/pep-0008/ Excellent suggestions. Frederic