tkinter/tk memory questions

Edward K. Ream edream at tds.net
Wed Dec 4 09:05:57 EST 2002


"Chad Netzer" <cnetzer at mail.arc.nasa.gov> wrote in message
news:mailman.1038971645.21706.python-list at python.org...

> Aha! Here is the problem:  When you "bind" in Tkinter, python has to
obtain
> an id from tcl (called a funcid), to use with unbind.  As a consequence
(and
> assuming I'm not overstating things), bind ALWAYS returns an new id (from
> tcl), and it is THAT id that you have to save and use with unbind.
>
> For an example (not with the canvas, but with bindings in general), look
at
> the Pmw source, in PmwBalloon.py, and see how they implement
> binding/unbinding, etc.


Yes. This works. No more leaks in my app. O frabjous day! Callooh! Callay!

For completeness, here is sample code that does the recycling:

# When creating tag bindings:
id1 = self.canvas.tag_bind(id, "<1>", v.OnBoxClick)
if self.recycleBindings:
  self.tagBindings.append((id,id1,"<1>"),)

# When creating text bindings:
id1 = t.bind("<1>", v.OnHeadlineClick)
if self.recycleBindings:
  self.bindings.append((t,id1,"<1>"),)

def deleteBindings (self):
  # Unbind all the tag bindings.
  for id,id2,binding in self.tagBindings:
    self.canvas.tag_unbind(id,binding,id2)
  self.tagBindings = []
  # Unbind all the text bindings.
  for t,id,binding in self.bindings:
    t.unbind(binding,id)
  self.bindings = []

Many thanks, Chad, for solving this mystery.  Please present this coupon the
next time you are in Madison Wisconsin.  It's good for lunch or dinner at
L'etoile, one of the best restaurants in the United States.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------





More information about the Python-list mailing list