菁英科技(卓目鸟学苑)- 专注软件测试菁英教育

标题: python_代金鑫_2021.01.27 [打印本页]

作者: 心向未来    时间: 2021-1-27 20:18
标题: python_代金鑫_2021.01.27
今天学习内容: 9:00-17:30
  完善计算器的按钮功能,以及举例bug解决
              def function(self):
        # 获取按键的内容
        text = self.sender().text()
        # 判断被按下的按钮,然后执行相应的操作
        if text == '<——':
            self.backspace()
        elif text == 'C' or text == 'CE':
            self.clear()
        elif text == 'Close':
            self.close()
        elif text == '=':
            self.calculate()
        else:
            self.write(text)
    def backspace(self):
        # 获取文本框的内容
        content = self.screen.text()
        # 向文本框写入内容
        self.screen.setText(content[:-1])
    def clear(self):
        '''清除显示器内容'''
        self.screen.setText('')
        
    def close(self):
        '''关闭计算器'''
        # self.screen.setText(QCoreApplication.instance().quit)
        QCoreApplication.quit()
    def calculate(self):
        '''计算结果'''
        content = self.screen.text()
        result = eval(content)
        self.screen.setText(str(result))
        
    def write(self,text):
        '''向显示器写入内容'''
        content = self.screen.text()
        if len(content) ==0:
            content = text
        elif content[-1] in '+-*/' and text in '+-*/':
            content = content[:-1] + text
        else:
            content = content + text
        # self.screen.setText(self.screen.text()+text)
        self.screen.setText(content)
创建一个文本编辑器
创建一个窗口,并给窗口添加状态栏
创建一个窗口,并给窗口添加菜单栏以及菜单条目
创建一个窗口,并给窗口添加工具栏
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml5832\wps3.jpg
HTML语言 创建一个网页
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml5832\wps4.jpg
18:20~20:30  整理笔记,对今天所学内容进行回顾复习






欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/) Powered by Discuz! X3.4