0

After I open my application, there would be a button that opens the second frame. so I want to tell my second frame to grab information based on a List that its value would be appended to by main frame.
For Example
In the main frame, there is self.pubID and after I do an action I append a number to that list. after than I open the second frame but it doesn't grab that value that I appended, means it can't get the updated information from that list. Thanks to you for your help. I know the code I gave looks awful but the whole script might be long and confusable to upload so I hope it shows something.

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        panel = wx.Panel(self, -1)

    def OnSelect(self, event):        
        item = event.GetSelection()
        del self.pubID[:]
        self.pubID.append(item)
    def onInsert(self, event):
            self.Lin = InLink("Insert")
            self.Lin.Show()
class InLink(wx.Frame):
    def __init__(self,title):
        wx.Frame.__init__(self, None, title=title, pos=(150,150), size=(200,200))    
        panel = wx.Panel(self)
pradyunsg
  • 18,287
  • 11
  • 43
  • 96
jesy2013
  • 319
  • 2
  • 12
  • I am a bit confused about what you're trying to do. I understand that `InLink` needs information from `MyFrame`. Will `InLink` return infromation back to `MyFrame`? – acattle Feb 25 '13 at 02:14

1 Answers1

1

If I understand correctly, InLink needs to know what's inside MyFrame.pubID. Well there's a simple solution to that problem: pass it to your constructor. So your InLink.__init__() becomes this:

class InLink(wx.Frame):
    def __init__(self,title, pubID):
        #now you can easily get the value from pubID
        ...

However, I think you have some problems in their code beyond just that. I posted a comment asking you to explain in more detail what you wanted to do. From reading your question I think you want InLink to return some value that that MyFrame will use. Is this correct? If so, instead of using a wx.Frame you should be using a wx.Dialog. Here is a previous SO post about wx.Dialogs. That answer contains links to other tutorials to help you get started.

Community
  • 1
  • 1
acattle
  • 3,073
  • 1
  • 16
  • 21
  • Thanks for both of you. I found a solution for what I wanted to do. for second class I passed Parent and then self.parent = parent. and so on.. then I can use any variable of my main frame by calling self.parent.pubID or whatever. – jesy2013 Feb 25 '13 at 03:48
  • @jesy2013 Oh, that's not a great idea. It will *work* but it kind of breaks [encapsulation](http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29). You **should** specify `MyFrame` as the parent of `InLink` because that way wxPython will link them together, but I think you should pass `pubID` explicitly, like in my answer. Otherwise `InLink` will always depend on a `MyFrame` existing. If `InLink` **cannot** exist with a `MyFrame` then maybe you should look at using a `wx.Dialog`. – acattle Feb 25 '13 at 04:03
  • thanks. well actually my InLink frame should depend on MyFrame and if MyFrame not exist then no InLink is necessary. Since I found it I used it a lot and it is very useful and till now I can't see any disadvantage of it. and it is not just about pubID, it is about calling anything from other classes. and if I use something like self.myframe=MyFrame(self) it is bad, do you know why? because it doesn't bring me the updated values from variables or wherever from MyFrame class. what do you think about this updated thing I mentioned? – jesy2013 Feb 26 '13 at 05:36