Я делаю небольшой калькулятор на Python3, используя tkinter. В разделе я встретил
TypeError: 'NoneType' object is not callable
Это раздел, в котором я вызвал функцию:
def key_in(event):
if (event.keysym == 'Return'):
calculate()
elif (event.keysym == 'BackSpace'):
delete() # or clear()
# elif and else statements
Я не обнаружил никаких ошибок в calculate
, но получаю это TypeError
в delete
и clear
# 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)
# ERROR (TypeError)
def clear():
"""Function to clear the whole *_expression*"""
global _expression, _equation
_expression = ''
_equation.set(_expression)
# 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