Python Temperature Conversion Mvc Style: Why Am I Getting "typeerror: Buttonpressed() Missing 1 Required Positional Argument: 'self'"
Solution 1:
In MyFrame.__init__
, you're saving a reference to the Controller
class:
self.controller = glue.Controller
But you're not actually creating an instance of Controller
, which means Controller.__init__
is never called. That's probably not what you meant to do.
It also means that when you do this:
self.convertButton["command"]=self.controller.buttonPressed
You're really saying
self.convertButton["command"]= glue.Controller.buttonPressed
Which means you're making an unbound method the callback for convertButton
. Unbound means that the method isn't bound to a particular instance of Controller
, which means self
won't implicitly be passed to it - hence the error you're getting. Your program is creating a Controller
instance when it starts, and that is what's calling MyFrame.__init__
. You're actually 99% of the way to do things properly - you're passing the Controller
instance to MyFrame.__init__
:
self.view = myFrame.MyFrame(self) #instantiates the VIEW
So now all you need to do is assign that instance to self.controller
Controller.init`:
def __init__(self, controller):
"""
places the controls on the frame
"""
tkinter.Frame.__init__(self)
self.pack()
self.controller = controller # NOT glue.Controller
Post a Comment for "Python Temperature Conversion Mvc Style: Why Am I Getting "typeerror: Buttonpressed() Missing 1 Required Positional Argument: 'self'""