名称错误:未定义名称“txtDisplay”

2024-09-30 23:46:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我用python3中的tkinter模块制作了一个科学计算器。当我运行代码时,它运行良好,直到我按下计算器上的任何键,然后它会给出以下错误:

C:\Users\Tauseef\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/Tauseef/Desktop/scratch.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Tauseef\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:/Users/Tauseef/Desktop/scratch.py", line 54, in <lambda>
    btn[i]["command"] = lambda x = numberpad[i]: added_value.numberEnter(x)
  File "C:/Users/Tauseef/Desktop/scratch.py", line 26, in numberEnter
    firstnum = txtDisplay.get()
NameError: name 'txtDisplay' is not defined

Tags: inpytkinterlocallinecallusersappdata