gpt4 book ai didi

Python 未绑定(bind)方法类型错误

转载 作者:太空狗 更新时间:2023-10-29 16:58:46 25 4
gpt4 key购买 nike

get_pos 方法应该获取用户在条目中输入的内容。当 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: unbound method get_pos() must be called with app instance as first argument (got nothing instead)

通俗地说,这意味着您正在做这样的事情:

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

很难得到比这更具体的信息,因为您没有向我们展示导致错误的实际代码。

关于Python 未绑定(bind)方法类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6012799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com