Reputation: 345
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()
Upvotes: 0
Views: 210
Reputation: 113988
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()
Upvotes: 2
Reputation: 5524
The error is that you included self
as an argument in your call to Login.apples()
. The first argument in a class method (usually called self
) should not be included in function calls (only function definitions), and is treated implicitly in Python. It is used to handle references within the class methods to the class itself (or other class attributes/functions). See this post for information on self
However, once you fix this, your code will still not run with the same error because you given no value to parent
or id
. You will need to provide values for these variables before asking python to call a function with them
Upvotes: 1