Skip to content Skip to sidebar Skip to footer

Python Temperature Conversion Mvc Style: Why Am I Getting "typeerror: Buttonpressed() Missing 1 Required Positional Argument: 'self'"

newbie-wanna-be python-programmer here. I had a homework assignment (that I couldn't get) and now that the class is over, I feel comfortable asking for help here. I'm still really

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.controllerController.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'""