我正在構建一個計算器。我得到了「NameError:name'self'沒有定義聲明」if self.op.Pending == True「的一部分代碼。我嘗試設置一些等於None的東西,但那並沒有擺脫錯誤。我該如何擺脫錯誤的?計算器:Python類中的名稱錯誤
class calculator():
def __init__(self):
self.total = 0
self.current = ""
self.newNumber = True
self.opPending = False
self.op = ""
self.eq = False
def numberPress (self, num):
self.eq = False
temp = textbox.get()
temp2 = str(num)
if self.newNumber:
self.current = temp2
self.newNumber = False
else:
if temp2 == '.':
if temp2 in temp:
return
self.current = temp + temp2
self.display(self.current)
def calcTotal(self):
self.eq = True
self.currrent = float(self.current)
if self.opPending == True: #ERROR
self.doSum()
else:
self.total = float(textbox.get())
謝謝,無法相信我忘了臺詞!現在,我有時間來構建GUI。 – user6067378
@ user6067378祝你好運! –