Search code examples
pythonfilewxpython

How to use multiple wxPython project files in one program?


I am trying to make a pretty big app with many different parts and windows. I decided that it would look a lot cleaner if I had some windows have their own file and then import them into the main file. I tried to do this but when I try to run the class, it gives the error of needing three arguments. I do not understand how I should go about doing this so any help will be greatly appreciated! Main file:

import wx
import Login
Login.apples(self,parent,id)
class oranges(wx.Frame):
    def __init__(self,parent, id):
        wx.Frame.__init__(self,parent,id,"Mail",size=(700,700))
        self.frame=wx.Panel(self)
if __name__=="__main__":
    app=wx.App(False)
    window=oranges(parent=None, id=-1)
    window.Show()
    app.MainLoop()

I get a NameError: name "self" is not defined.

import wx
class apples(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,"Login to Mail",size=(400,400))
        self.frame=wx.Frame(self)



if __name__=="__main__":
    app=wx.App(False)
    window=apples(parent=None, id=-1)
    window.Show()
    app.MainLoop()

Solution

  • import wx
    import Login
    #Login.apples(self,parent,id) #this line wont work ... there is no self here...
    #see below in the if __name__ == "__main__" part
    class oranges(wx.Frame):
        def __init__(self,parent, id):
            wx.Frame.__init__(self,parent,id,"Mail",size=(700,700))
            self.frame=wx.Panel(self)
    if __name__=="__main__":
        app=wx.App(False)
    
        window=oranges(parent=None, id=-1)
        other_window = Login.apples(parent=None,id=-1)
        window.Show()
        other_window.Show()
        app.MainLoop()