0

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()
user3818089
  • 345
  • 1
  • 2
  • 19

2 Answers2

2
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()
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • The Login window never opens. Any ideas? – user3818089 Dec 01 '14 at 22:43
  • Ok thanks it works now except the window shows up in gray inside of white and I can't do add a button or anything. – user3818089 Dec 01 '14 at 22:49
  • 1
    Im guessing thats maybe cause of this line or something `self.frame=wx.Frame(self)` ... maybe try `self.panel=wx.Panel(self)` as frame is a funny choice for that .. – Joran Beasley Dec 01 '14 at 22:53
  • I have one last quick question, is this the best way to have one window pop up after one has completed its process? – user3818089 Dec 01 '14 at 23:06
  • I have the one window for logging in and when the login is complete , I want the main window to show up. – user3818089 Dec 01 '14 at 23:17
  • your login window should probably be a wx.Dialog that is shown modally ... and it should appear on top of your other frame ... or better yet just have a login space in the main frame ... I dislike popups in general – Joran Beasley Dec 01 '14 at 23:19
  • 1
    An example of a login frame and a main frame http://stackoverflow.com/questions/26602008/wxpython-show-dialog-on-main-frame-startup/26616375#26616375 – Yoriz Dec 02 '14 at 00:29
1

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

Community
  • 1
  • 1
wnnmaw
  • 5,444
  • 3
  • 38
  • 63