Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
`类型错误:';非类型';对象在Python3.8.2的tkinter中不可调用_Python_Python 3.x_Function_Tkinter_Tkinter Entry - Fatal编程技术网

`类型错误:';非类型';对象在Python3.8.2的tkinter中不可调用

`类型错误:';非类型';对象在Python3.8.2的tkinter中不可调用,python,python-3.x,function,tkinter,tkinter-entry,Python,Python 3.x,Function,Tkinter,Tkinter Entry,我正在用tkinter在Python3上制作一个小计算器。在一节中,我遇到了 TypeError:“非类型”对象不可调用 这是我调用函数的部分: def key_in(event): if (event.keysym == 'Return'): calculate() elif (event.keysym == 'BackSpace'): delete() # or clear() # elif and else statement

我正在用tkinter在Python3上制作一个小计算器。在一节中,我遇到了
TypeError:“非类型”对象不可调用

这是我调用函数的部分:

def key_in(event):

    if (event.keysym == 'Return'):
        calculate()

    elif (event.keysym == 'BackSpace'):
        delete()  # or clear()

    # elif and else statements
我在
calculate
中没有遇到任何错误,但我在
delete
clear
中得到了这个
TypeError

# ERROR (TypeError)
def delete():
    """Responsive function to delete the last entered character"""
    global _expression, _equation    # _expression = '<expression>', _equation = tkinter.StringVar()

    try:
        if (_expression[-1] != ' '):
            _expression = _expression[0:-1:1]

        else:
            _expression = _expression[0:-3:1]

    except IndexError:
        pass

    _equation.set(_expression)
我怎样才能解决这个问题

实际误差:

Exception in Tkinter callback
Traceback (most recent call last):
    File "C:\Users\SpiderMan\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
        return self.func(*args)
    File "G:\Python Programs\Calculator.py", line 489, in key_in
        delete()
TypeError: 'NoneType' object is not callable
问题不在于
delete
,问题在于在您调用它时,
delete
None
,而不是您认为它是的函数。最有可能的是,在定义函数后,您将值
None
分配给名称
delete
,因此这是
键在执行名称
delete
查找时看到的值。问题不在
delete
,问题是在调用它的位置,
delete
None
,而不是您认为的功能。很可能,在定义函数后,您将值
None
分配给了名称
delete
,因此这是
键在执行名称
delete
查找时看到的值。
# NO ERROR
def calculate():
    """Enters the calculated value of the expression
to the text box while handling errors
"""
    global _expression, _equation

    try:
        try:
            # Function `evaluate` will convert and calculate the `_expression` into a python
            # understandable code and function `str` will convert the result into string
            _expression = str(evaluate(_expression))
            _equation.set(_expression)

        except ZeroDivisionError:
            _equation.set('∞')
            _expression = ""

    except:
        _equation.set("ERROR")
        _expression = ""
Exception in Tkinter callback
Traceback (most recent call last):
    File "C:\Users\SpiderMan\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
        return self.func(*args)
    File "G:\Python Programs\Calculator.py", line 489, in key_in
        delete()
TypeError: 'NoneType' object is not callable