Python未绑定方法TypeError [英] Python Unbound Method TypeError
问题描述
方法get_pos
应该可以捕获用户在条目中输入的内容.执行get_pos
时,它返回:
The method get_pos
is supposed to grab what the user inputs in the entry. When get_pos
is executed, it returns with:
TypeError:未绑定方法get_pos()必须以应用程序实例作为第一个参数来调用(取而代之的是
TypeError: unbound method get_pos() must be called with app instance as first argument (got nothing instead)
代码:
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
推荐答案
您报告了此错误:
TypeError:未绑定方法get_pos()必须以应用程序实例作为第一个参数来调用(取而代之的是
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()
您需要做的是这样的:
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.
这篇关于Python未绑定方法TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!