TKinter and GC

howard at eegsoftware.com howard at eegsoftware.com
Wed Sep 13 16:41:55 EDT 2000


OK, you have me worried now.

I have an application in development which has various tkinter 
menus/option screens which I create and destroy as needed.

In some of the tkinter objects I keep references to Python (class) 
objects which the tkinter screens display/alter.  When I destroy the 
tkinter objects, does this mean I still have reference counts to the 
Python objects I assigned in the tkinter objects? 

I got stuck in this (design) mess because I have a design with user-
'created' widgets which can have a changing 'meaning', each with its 
own set of data.  Users can delete the top level widgets ( and I get
to 
clean up all the underlaying objects).

A (clipped) example:

class Command:
    def __init__(self,func,*args,**kw):
        self.func=func
        self.args=args
        self.kw=kw
    def __call__(self,*args,**kw):
        args=self.args+args
        kw.update(self.kw)
        apply(self.func,args,kw)

def make_mode_entry(scanv,initial_text):
    "creates main 'mode' entry box"
   
    ef=Frame(scanv.root,relief='ridge',borderwidth=3)
    lb=Label(ef,text=initial_text,width=6,anchor='w')
    bw=Button(ef,width=9,text='Mode', \                        
command=Command(change_feedback_mode,lb,0))
    bw.pack(side='left')
    lb.pack(side='right')

    wew=scanv.create_window(0,g.rightpos,window=ef,anchor='nw')
 (end of clip)

Does the reference to "lb" in the command class and the window 
"ef" in the canvas create_window mean that destroying the tkinter 
frame "ef" still leaves those objects with reference counts?

I am suddenly worried that I have to (like in C) 'remember' every 
allocated object and explicitly delete it.

Any explanations ...please....

Howard Lightstone
EEGSoftware
howard at eegsoftware.com



More information about the Python-list mailing list