Mailing List Archive

How to kill an object? (or Debugging reference counts)
--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii

I've attached a simple Tk script that illustrates the problem.

How do I kill "group"?

Something is hanging onto it for dear life and won't let go.
I want to delete group (a PlaceableGroup instance), and let it delete its
Tk representation.

Randall

--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="immortal.py"

#!/usr/bin/env python

from Tkinter import *
from Canvas import *

class PlaceableGroup( Group ):

def __init__( self, canvas, tag = None ):
Group.__init__( self, canvas, tag )
self.canvas = canvas
Widget.bind( self.canvas, "<Button-1>", self.__MouseDownCB )

def __del__( self ):
print "del method invoked"
self.unbind()
self.delete()

def unbind( self ):
Widget.unbind( self.canvas, "<Button-1>" )

def __MouseDownCB( self, event ):
rect = Rectangle( self.canvas, event.x-5, event.y-5,
event.x+5, event.y+5 )
self.addtag_withtag( rect )

root = Tk()
canvas = Canvas( root )
canvas.pack()
btn = Button( text="Click canvas, and hit me to destroy the group",
command=root.quit )
btn.pack()
group = PlaceableGroup( canvas )
root.mainloop()

#
# We would like to kill "group" here, but no such luck
#
group = None
btn.configure( text="You'd think the group wasn't bound anymore, but..." )
root.mainloop()

--RnlQjJ0d97Da+TV1--