import sys from calculator import Ui_MainWindow from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class calculator(QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.count = [] self.front = 0 self.double = 0 self.choice = '+' @pyqtSlot() def on_pushButton0_clicked(self): self.count.append(0) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton1_clicked(self): self.count.append(1) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton2_clicked(self): self.count.append(2) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton3_clicked(self): self.count.append(3) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton4_clicked(self): self.count.append(4) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton5_clicked(self): self.count.append(5) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton6_clicked(self): self.count.append(6) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton7_clicked(self): self.count.append(7) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton8_clicked(self): self.count.append(8) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton9_clicked(self): self.count.append(9) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) if __name__ == '__main__': app = QApplication(sys.argv) ui = calculator() ui.show() sys.exit(app.exec_())
时间: 2024-04-19 07:28:02 浏览: 144
rg.rar_QT calculator_qt计算器_rg.rar
这是一个使用PyQt5实现的一个简单的计算器界面程序。该程序定义了一个名为`calculator`的类,继承自`QMainWindow`和`Ui_MainWindow`。在构造函数中初始化了一些变量,并连接了按钮的点击事件到对应的槽函数。
每个数字按钮的点击事件都会将对应的数字添加到`self.count`列表中,并根据列表中的数字计算出当前结果,并显示在`lcdNumber`上。
最后,通过创建`QApplication`对象和`calculator`对象,显示计算器界面,并进入主事件循环。
请注意,为了运行该程序,你需要确保已经安装了PyQt5和相关的依赖库。
阅读全文