我想这就是你想要的class Calc:
numbers = []
operators = []
...
def pressed(self,widget): #This functions makes possible that the label of a button is displayed in the textbox when that button is pressed
num = self.textbox.get_text()
pnum = widget.get_label()
result = ""
if pnum in "1234567890.":
self.textbox.set_text(num + pnum)
return
elif pnum == "x":
self.numbers.append(float(num))
self.operators.append(operator.mul)
elif pnum == "+":
self.numbers.append(float(num))
self.operators.append(operator.add)
elif pnum == "-":
self.numbers.append(float(num))
self.operators.append(operator.sub)
elif pnum == "/":
self.numbers.append(float(num))
self.operators.append(operator.div)
elif pnum == "sqrt":
self.numbers.append(float(num)**0.5)
elif pnum == "=":
self.numbers.append(float(num))
for op in self.operators:
self.numbers.insert(0, op(self.numbers.pop(0),self.numbers.pop(0)))
result = str(self.numbers[0])
self.textbox.set_text(result)