我的账户
啄木鸟学院

专注软件测试菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

python_代金鑫_2021.01.27

[复制链接]
心向未来学员认证 发表于 2021-1-27 20:18:40 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
今天学习内容 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  整理笔记,对今天所学内容进行回顾复习

回复

使用道具 举报

关注0

粉丝0

帖子23

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注软件测试菁英教育

客服电话:17792550360

客服时间:9:00-21:00

卓目鸟学苑 - 专注软件测试菁英教育!( 陕ICP备2025058934号-2 )

版权所有 © 西安菁英教育科技有限公司 2023-2026