Python 未绑定方法类型错误 [英] Python Unbound Method TypeError

查看:29
本文介绍了Python 未绑定方法类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法 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: unbound method 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() 必须以应用程序实例作为第一个参数调用(什么都没有)

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 未绑定方法类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆