60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
From: aa8vb at vislab.epa.gov (Randall Hopper)
|
|
Date: Tue, 4 May 1999 12:08:03 -0400
|
|
Subject: How to kill an object? (or Debugging reference counts)
|
|
Message-ID: <19990504120803.A55620@vislab.epa.gov>
|
|
Content-Length: 1287
|
|
X-UID: 1791
|
|
|
|
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
|
|
-------------- next part --------------
|
|
#!/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()
|
|
|
|
|