[Tkinter-discuss] Canvas tag bindings not going away?

Bob Greschke bob at passcal.nmt.edu
Tue Sep 1 22:08:42 CEST 2009

> If I understand you correctly, what you describe is what I think that
> tag bindings are supposed to do. I tried the following:
>>>> from Tkinter import *
>>>> c = Canvas()
>>>> c.pack()
>>>> def test(ev):
> ...     print 'foo'
> ...
>>>> c.tag_bind('tag_foo', '<1>', test)
>>>> c.create_rectangle(0, 0, 100, 100, fill='blue', tags=('tag_foo'))
> 1
>>>> foo
> foo
> foo
> foo
> The "foo"s at the end of the snippet are of course from clicking the
> blue rectangle. The point here is, that the tag-binding is obviously
> active without any items being created, and I believe that is exactly
> what it is for; if you want the binding to be removed when the item is
> deleted, you should bind to the item-id instead, or maybe use
> tag_unbind() to remove the bindings.
> I hope this helps
> Michael

You are too smart.  I've only been goofing with this stuff for about 7  
years.  Looking through my code I now understand that I didn't know  
anything. :)  I've been binding to the tag in some places and to the  
"ID" of the create_x item in others.  NOW I get it!  That's exactly  
what was going on.  A big thanks!


More information about the Tkinter-discuss mailing list