Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25053

Tkinter.event.widget: handler gets name instead of widget.

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <anthra.norell@bluewin.ch>
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; 'width': 0.07; 'x-mailer:evolution 2.28.3': 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; 'tracing': 0.09; 'def': 0.10; 'yet.': 0.13; "('',": 0.16; '(len': 0.16; 'ans': 0.16; 'frames': 0.16; 'labels,': 0.16; 'received:195.186': 0.16; 'received:bluewin.ch': 0.16; 'side.': 0.16; 'instance,': 0.17; 'widget': 0.17; 'skip:" 30': 0.20; 'skip:" 40': 0.20; 'event,': 0.22; "haven't": 0.23; 'skip:[ 10': 0.26; '(most': 0.27; '2.6': 0.27; 'label': 0.27; 'correct': 0.28; 'rest': 0.28; 'record': 0.28; 'manual': 0.29; '"the': 0.29; 'class': 0.29; 'file': 0.32; 'print': 0.32; 'event.': 0.33; 'traceback': 0.33; 'ubuntu': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'entered': 0.34; 'wrong': 0.34; 'done': 0.34; 'list': 0.35; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'build': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'red': 0.60; 'range': 0.60; 'containing': 0.61; 'first': 0.61; 'side': 0.61; 'latest': 0.61; 'here': 0.65; 'anchor': 0.65; 'records': 0.68; 'received:ch': 0.69; 'occasion': 0.84; 'subject:gets': 0.84; 'relief': 0.93; 'labels.': 0.97
Subject Tkinter.event.widget: handler gets name instead of widget.
From Frederic Rentsch <anthra.norell@bluewin.ch>
To python-list@python.org
Content-Type text/plain; charset="UTF-8"
Date Sun, 08 Jul 2012 23:19:13 +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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1927.1341782432.4697.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341782432 news.xs4all.nl 6924 [2001:888:2000:d::a6]:38270
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25053

Show key headers only | View raw


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."
	Ans so it is--has been until on the latest occasion "event.widget" was
not the widget, but its name, crashing the handler. 	
# 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)):
	record = records [n]
	line_frame = Frame (self, name = '-%d-' % n, relief = RAISED, **BUTTON_FRAME_)
	line_frame.bind ('<Enter>', self.enter)
	line_frame.bind ('<Leave>', self.leave)
	line_frame.bind ('<ButtonRelease-1>', self.pick_record)
	line_frame.bind ('<ButtonRelease-3>', 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)

# Here is the <Enter> 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 <Tkinter.Event instance at 0x9115dcc> .main-frame.data-frame.title-hit-list.-10- <type 'str'>
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 <Leave>. 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


Frederic

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch <anthra.norell@bluewin.ch> - 2012-07-08 23:19 +0200

csiph-web