python - `TypeError: 'NoneType' object is not callable` 在 tkinter,Python 3.8.2
问题描述
我正在使用 tkinter 在 Python3 上制作一个小型计算器。在一个部分中,我遇到了
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
解决方案
推荐阅读
- unity3d - 使用 Addressables 时精灵显示不正确
- azure - 自定义图形连接器中的 Azure AD 标识映射
- webpack - 如何强制 vue/webpack 在别名文件夹上使用与源根目录相同的 linter
- sql - 重叠生效日期聚合
- slatejs - Slatejs editor.selection 在弹出框上返回 null?
- c - 仅包含字符的结构是否无填充?
- c++ - 将 winusb dll 添加到代码块
- powershell - Powershell 脚本不写正确的变音符号 - Powershell 本身可以
- javascript - 在Javascript中获取“输入意外结束”
- python - 在页面刷新时更新 Plotly Dash 图