17
votes

The method get_pos is supposed to grab what the user inputs in the entry. When get_pos is executed, it returns with:

TypeError: unbound method get_pos() must be called with app instance as first argument (got nothing instead)

Code:

class app(object):
    def __init__(self,root):
        self.functionframe=FunctionFrame(root, self)
            self.functionframe.pack(side=BOTTOM)
    def get_pos(self):
        self.functionframe.input(self)
class FunctionFrame(Frame):
    def __init__(self,master,parent):
        Frame.__init__(self,master,bg="grey90")
        self.entry = Entry(self,width=15)
        self.entry.pack
    def input(self):
        self.input = self.entry.get()
        return self.input
3
Where's the code for the entry method? - Keith
Still not enough information here. Where are you actually calling get_pos()? - Keith
get_pos() is binded to a button and I have tested that all the binds work fine - Steven
One of the problems here is the last method is assigning an attribute with the same name as the method (input), thus making the method disappear. Future references to functionframe.input will get whatever self.entry.get() returned. - Keith

3 Answers

45
votes

You reported this error:

TypeError: unbound method get_pos() must be called with app instance as first argument (got nothing instead)

What this means in layman's terms is you're doing something like this:

class app(object):
    def get_pos(self):
        ...
...
app.get_pos()

What you need to do instead is something like this:

the_app = app()  # create instance of class 'app'
the_app.get_pos() # call get_pos on the instance

It's hard to get any more specific than this because you didn't show us the actual code that is causing the errors.

16
votes

I've run into this error when forgetting to add parentheses to the class name when constructing an instance of the class:

from my.package import MyClass

# wrong
instance = MyClass

instance.someMethod() # tries to call MyClass.someMethod()

# right
instance = MyClass()


instance.someMethod()
3
votes

My crystal ball tells me that you are binding app.get_pos to a button using the class app (which really should be called App) instead of creating an instance app_instance = app and using app_instance.get_pos.

Of course as others have pointed out there are so many other issues with the code you did post it is a bit hard to guess at the mistakes in the code you didn't post.