Using an object inside a class

Ian Kelly ian.g.kelly at
Mon Jan 23 17:57:00 EST 2012

On Mon, Jan 23, 2012 at 3:45 PM, Jonno <jonnojohnson at> wrote:
> I see, so that would get me access to the app instance during init of Class1
> but if I can't access frame or the object as they still aren't created yet.
> I can only do that in attributes that I know won't be called until the app
> is created.

Yeah, that's a good point.  In that case, that code really doesn't
belong in the Class1 __init__ method, as it depends on the whole
hierarchy having already been properly initialized.  Instead, I
suggest using the wx.CallAfter function to schedule that code for when
the event loop has actually been started.  For example:

class Class1(wx.Panel):
    def __init__(self, parent, id = -1, dpi = None, **kwargs):
        # Do all your initialization stuff.  Then:

    def _init_graph_panel(self):

By the way, looking at your object hierarchy more closely, isn't
"app.frame.graph_panel" going to end up being the same thing as just
"self.figure"?  Why not just use the latter and remove the reliance on
finding the correct frame?


More information about the Python-list mailing list