Help save net neutrality! Learn more.

Problem showing another frame

  • Rob Cridland

    Rob Cridland - 2009-07-25


    1st question (nervous!)

    I have created an App1 and a Frame1.  Within Frame1 I've created a button and a on button event.  I've then added a Frame2 to the App1.  However, when I add the following code to the on button event :

    def OnButton1Button(self, event):

    The compiler says "AttributeError : 'Frame1 object has no attribute 'Frame2'

    What am I doing wrong here?

    Many thanks

    • Chelonian

      Chelonian - 2009-07-25

      Hi, welcome. 

      This is more of a Python or wxPython issue, not really a Boa issue.  But that's fine.  The problem is that, as the error says, Frame1 doesn't have any reference to Frame2, in other words when you mention Frame2, Frame1 doesn't know what that is because it is not defined anywhere within Frame1.  You can check yourself in Frame1's code and see that nowhere does it say Frame2 = something.  It is instead defined within App1, not Frame1.  App1 knows what Frame2 is. 

      This gets into the issue of sending information between classes/Frames.  Tricky for beginners, but important to get clear.

      So, what you can do is tell App1 to show Frame2.  You can do this in several different ways.  One quick one is this:

      def OnButton1Button(self, event):
 =  wx.GetApp()   #This will get a reference to the app into Frame1.

      The dots notation is key.  The dots in that last line mean this in words:

      "I, Frame1 ("self") have a reference to the main app ("app"),
      which in turn has a reference to Frame2 ("Frame2"), which in
      turn has a method called .Show()"

      As you get more comfortable, you should look into coding practices
      to keep classes as independent of each other as possible.  For
      now though, this should work.

    • Chelonian

      Chelonian - 2009-07-25

      (Sorry about the lack of indents...the forum seemed to remove them).

    • Rob Cridland

      Rob Cridland - 2009-07-27

      Thanks for the reply (and don't worry about the indents!)

      However, I'm now getting this error :

      AttributeError : 'BoaApp' object has no attribute 'Frame2'



Log in to post a comment.