呆瓜的泡椒鸡 2023-02-27 19:45 采纳率: 62.5%
浏览 17

这个计算器为什么运行不出来

def OnKeyTyped(self, event):    #直接键盘输入
    self.calculation = event.GetString()
'''
定义每一个按钮的操作
'''
def one(self, event):
    self.calculation = self.calculation + "1"
    self.inputField.SetValue(self.calculation)

def two(self, event):
    self.calculation = self.calculation + "2"
    self.inputField.SetValue(self.calculation)

def three(self, event):
    self.calculation = self.calculation + "3"
    self.inputField.SetValue(self.calculation)

def four(self, event):
    self.calculation = self.calculation + "4"
    self.inputField.SetValue(self.calculation)

def five(self, event):
    self.calculation = self.calculation + "5"
    self.inputField.SetValue(self.calculation)

def six(self, event):
    self.calculation = self.calculation + "6"
    self.inputField.SetValue(self.calculation)

def seven(self, event):
    self.calculation = self.calculation + "7"
    self.inputField.SetValue(self.calculation)

def eight(self, event):
    self.calculation = self.calculation + "8"
    self.inputField.SetValue(self.calculation)

def nine(self, event):
    self.calculation = self.calculation + "9"
    self.inputField.SetValue(self.calculation)

def zero(self, event):
    self.calculation = self.calculation + "0"
    self.inputField.SetValue(self.calculation)

def clear(self, event):
    self.calculation = ""
    self.inputField.SetValue(self.calculation)

def plus(self, event):
    self.calculation = self.calculation + "+"
    self.inputField.SetValue(self.calculation)

def minus(self, event):
    self.calculation = self.calculation + "-"
    self.inputField.SetValue(self.calculation)

def multiply(self, event):
    self.calculation = self.calculation + "*"
    self.inputField.SetValue(self.calculation)

def divide(self, event):
    self.calculation = self.calculation + "/"
    self.inputField.SetValue(self.calculation)

def point(self, event):
    self.calculation = self.calculation + "."
    self.inputField.SetValue(self.calculation)

def left(self, event):
    self.calculation = self.calculation + "("
    self.inputField.SetValue(self.calculation)

def right(self, event):
    self.calculation = self.calculation + ")"
    self.inputField.SetValue(self.calculation)

def backspace(self,event):
    self.calculation = self.calculation[0:-1:1]
    self.inputField.SetValue(self.calculation)

def equal(self, event):
    try:
        result = eval(self.calculation)    #计算式求值
        self.inputField.Insert(self.calculation, 0)    #将历史记录加入下拉框
        self.inputField.SetValue(str(result))    #输出框值为结果
    except Exception as e:
        self.inputField.SetValue('Input Illegal')
        print(e)
        return
    finally:
        self.calcuation = ""

if name == 'main':
app = wx.App()
frame = Calculator(parent=None, id=-1)
frame.Show()
app.MainLoop()

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-02-27 22:46
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 2月27日

悬赏问题

  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding