as beginner in wxpthon, i'm creating simple login script creates 2 buttons: 1 open window user create account, , 1 them register account. relevant code is:
yesbutton = wx.button(panel, label="yes, wish log in", pos=(50,150), size=(150,60)) self.bind(wx.evt_button, login.login(login), yesbutton) nobutton = wx.button(panel, label="no, wish register", pos=(270,150), size=(150,60)) self.bind(wx.evt_button, register.register(register), nobutton) class login: def login(self): print("login") class register: def register(self): print("register") however when run code get:
typeerror: unbound method login() must called login instance first argument (got classobj instance instead)
i've looked lot answer, can't make solutions work. in advance.
your functions login.login() , register.register() take no arguments, you're passing login , register classes them. second line should instead be:
self.bind(wx.evt_button, login.login, yesbutton) you don't need parentheses after login.login in case since it's within bind function. adjust other binding.
edit: need instantiate login object , register object before calling classes. unfortunately don't have access wxpython @ moment , can't test it, try this:
edit 2: pass event function, make sure functions calling account this.
yesbutton = wx.button(panel, label="yes, wish log in", pos=(50,150), size=(150,60)) log = login() self.bind(wx.evt_button, log.login, yesbutton) nobutton = wx.button(panel, label="no, wish register", pos=(270,150), size=(150,60)) reg = register() self.bind(wx.evt_button, reg.register, nobutton) class login: def login(self, evt): print("login") class register: def register(self, evt): print("register")
Comments
Post a Comment