[Python-bugs-list] [ python-Bugs-531262 ] Wrong result for Canvas.tag_bind(t, s)
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 22 Mar 2002 08:44:00 -0800
Bugs item #531262, was opened at 2002-03-18 04:07
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=531262&group_id=5470
Category: Tkinter
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Eric Brunel (ebrunel)
>Assigned to: Nobody/Anonymous (nobody)
Summary: Wrong result for Canvas.tag_bind(t, s)
Initial Comment:
When a binding is defined for a tag in a Tkinter
Canvas, trying to get the callback using the
"tag_bind" method with 2 parameters returns a useless
value:
----------------------------
from Tkinter import *
root = Tk()
## Create the canvas
c = Canvas(root)
c.pack()
## Create the item
tId = c.create_text(100, 100, text='spam')
## Create the binding
def foo(event): print 'bar'
c.tag_bind(tId, '<Button-1>', foo)
## Get and print the binding
print c.tag_bind(tId, '<Button-1>')
root.mainloop()
---------------------------
The programs prints something looking like: 'if
{"[136128196foo %# %b %f %h %k %s %t %w %x %y %A %E
%K %N %W %T %X %Y %D]" == "break"} break'. Trying to
pass this value as the third parameter of tag_unbind
for example results in a TclError:
Traceback (most recent call last):
File "tkCanvasBindings2.py", line 16, in ?
c.tag_unbind(tId, '<Button-1>', f)
File "/usr/local/lib/python2.1/lib-tk/Tkinter.py",
line 1904, in
tag_unbind
self.deletecommand(funcid)
File "/usr/local/lib/python2.1/lib-tk/Tkinter.py",
line 297, in
deletecommand
self.tk.deletecommand(name)
TclError: can't delete Tcl command
This happens apparently on all platforms (tried
Win2K, Linux Mandrake 8.0 and Solaris 2.7).
----------------------------------------------------------------------
>Comment By: A.M. Kuchling (akuchling)
Date: 2002-03-22 11:44
Message:
Logged In: YES
user_id=11375
I don't think this is actually a bug, and the return
value of tag_bind really is useless. tag_bind(t,s)
returns the command bound to that sequence.
Tkinter.py supports a feature where a binding can
return the string "break" if no further bound function
should be invoked, so when adding a binding, Python has
to synthesize the 'if {123456foo ...}' Tcl command, and
that's what tag_bind returns.
I think your example code should be written as:
bind_id = c.tag_bind(tId, '<Button-1>', foo)
And then refer to bind_id when you need to delete the
binding.
Was your example usage of tag_bind() described in some
documentation, or in a demo script somewhere?
Maybe that script or documentation needs to be fixed.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=531262&group_id=5470