我在试着做一个简单的计算器,有0-9,加号,减号,clear和equals的按钮。我有图形用户界面和按钮的功能,但我的计算器计算的远不止999。有什么想法吗?
-如果你看第45-53行,我试图阻止它计算超过999。
这是我的代码:from tkinter import *
class Calculator(Frame):
def frame(this, side):
w = Frame(this)
w.pack(side=side, expand=YES, fill=BOTH)
return w
def button(this, root, side, text, command=None):
w = Button(root, text=text, command=command)
w.pack(side=side, expand=YES, fill=BOTH)
return w
need_clr = False
def digit(self, digit):
if self.need_clr:
self.display.set('')
self.need_clr = False
self.display.set(self.display.get() + digit)
def sign(self):
need_clr = False
cont = self.display.get()
if len(cont) > 0 and cont[0] ==