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; 'exception': 0.03; 'attribute': 0.05; '(self,': 0.07; 'column': 0.07; 'tkinter': 0.07; 'versions.': 0.07; 'width': 0.07; 'python': 0.09; '(0,': 0.09; 'bindings': 0.09; 'callback': 0.09; 'event):': 0.09; 'handler.': 0.09; 'handlers': 0.09; 'raised,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'release,': 0.09; 'tcl/tk': 0.09; 'terry': 0.09; 'tracing': 0.09; 'bug': 0.10; 'def': 0.10; 'yet.': 0.13; "('',": 0.16; '(len': 0.16; '3.3,': 0.16; 'ans': 0.16; 'frames': 0.16; 'labels,': 0.16; 'message- id:@dough.gmane.org': 0.16; 'program?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'record,': 0.16; 'reedy': 0.16; 'side.': 0.16; 'widgets.': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'widget': 0.17; 'jan': 0.18; 'previously': 0.18; 'code,': 0.18; 'windows': 0.19; 'skip:" 30': 0.20; 'skip:" 40': 0.20; 'event,': 0.22; 'example': 0.23; "haven't": 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'skip:[ 10': 0.26; '(most': 0.27; '2.6': 0.27; 'label': 0.27; 'skip:e 30': 0.27; 'correct': 0.28; 'header:X -Complaints-To:1': 0.28; 'rest': 0.28; 'post': 0.28; 'record': 0.28; 'manual': 0.29; '"the': 0.29; 'class': 0.29; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'event.': 0.33; 'traceback': 0.33; 'ubuntu': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'entered': 0.34; 'wrong': 0.34; 'done': 0.34; 'list': 0.35; 'pm,': 0.35; 'posting': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'build': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'red': 0.60; 'range': 0.60; 'containing': 0.61; 'first': 0.61; 'side': 0.61; 'latest': 0.61; 'within': 0.64; 'here': 0.65; 'anchor': 0.65; 'records': 0.68; 'fields,': 0.84; 'occasion': 0.84; 'received:fios.verizon.net': 0.84; 'subject:gets': 0.84; 'relief': 0.93; 'labels.': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Tkinter.event.widget: handler gets name instead of widget. Date: Mon, 09 Jul 2012 01:58:48 -0400 References: <1341782353.2041.136.camel@hatchbox-one> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <1341782353.2041.136.camel@hatchbox-one> 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: 1341813557 news.xs4all.nl 6873 [2001:888:2000:d::a6]:56092 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25066 On 7/8/2012 5:19 PM, Frederic Rentsch wrote: > Hi widget wizards, > > The manual describes the "event" attribute "widget" as "The widget > which generated this event. This is a valid Tkinter widget instance, not > a name. This attribute is set for all events." Same in 3.3, with nice example of using it. def turnRed(self, event): event.widget["activeforeground"] = "red" self.button.bind("", self.turnRed) > Ans so it is--has been until on the latest occasion "event.widget" was > not the widget, but its name, crashing the handler. Has event.widget been the widget only in other programs or previously with the same program? > # Here I build a list of selectable records having each four fields. > # The fields are labels. The selectable line is a frame containing the > # labels side by side. The line frames go into self, which is a Frame. > > for n in range (len (records)): for n, record in enumerate(records): > record = records [n] > line_frame = Frame (self, name = '-%d-' % n, relief = RAISED, **BUTTON_FRAME_) > line_frame.bind ('', self.enter) > line_frame.bind ('', self.leave) > line_frame.bind ('', self.pick_record) > line_frame.bind ('', self.info_profile) > line_frame.grid (row = n+2, column = 1) > for i in self.range_n_fields: # (0, 1, 2, 3) > field = Label (line_frame, text = record [self.INDICES [i]], anchor = W, width = self.COLUMN_WIDTHS [i], **DB_LIST_LABEL_) > field.grid (row = 0, column = i, sticky = NW) 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'? > # Here is the handler: > > def enter (self, event): > w = event.widget > print 'hit list.enter (). Event, widget', event, w, w.__class__ # Tracing line > w.config (bg = SELECTED_BG_COLOR) > > # And here is what comes out. The first line is my tracing line. The name is correct in that it > # names the entered line_frame, but is wrong because it should be the line_frame, not its name. > # The rest is the red exception message: > > hit list.enter (). Event, widget .main-frame.data-frame.title-hit-list.-10- > Exception in Tkinter callback > Traceback (most recent call last): > File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__ > return self.func(*args) > File "/home/fr/python/finance/piam/hit_list.py", line 83, in enter > w.config (bg = SELECTABLE_BG_COLOR) > AttributeError: 'str' object has no attribute 'config' > > # The same thing happens with . The other handlers I haven't done yet. The same bindings work well in > # a Menu class with the difference that the bindings are on the Labels, not a containing Frame. > > # Dell E6500, Ubuntu 10.04, Python 2.6 You might try a current Python release, and the latest tcl/tk 8.5.11 released last March (comes with 3.3.0 Windows release, don't know how on Ubuntu). There might be (have been?) a bug with events on Frames, or on Frames within Frames treated as widgets. -- Terry Jan Reedy