[Tutor] Class instantiation of a GUI app

Jeff Shannon jeff@ccvcorp.com
Tue, 16 Oct 2001 09:45:22 -0700

> From: "Sharriff Aina" <nhytro-python@web.de>
> class MainApp:
> ....def __init__(self, root=0):
> ........# create main application
> ........root = Tk()

This snippet has another problem, in that once the __init__() function ends, root goes out of scope and is garbage-collected--this is probably not what you want.  (It may work if you call root.mainloop() at the end of
this function, and the entire app is *intended* to shut down once __init__() finishes, though this seems like an odd design to me...)

You probably want to save a reference to root as a member variable.  Try using

        self.root = Tk()

instead, and make all your other references to root be for self.root, as well.

Jeff Shannon
Credit International