import sys from PyQt5.QtWidgets import QApplication, QWidget , QMainWindow from Calui1 import Ui_Form class Mywindow(QWidget,Ui_Form): def __init__(self): super(Mywindow,self).__init__() self.setupUi(self) def btnClear_clicked(self): self.lineEdit.clear() def btn1(self): self.lineEdit.insert("1") def btn2(self): self.lineEdit.insert("2") def btn3(self): self.lineEdit.insert("3") def btn4(self): self.lineEdit.insert("4") def btn5(self): self.lineEdit.insert("5") def btn6(self): self.lineEdit.insert("6") def btn7(self): self.lineEdit.insert("7") def btn8(self): self.lineEdit.insert("8") def btn9(self): self.lineEdit.insert("9") def btn0(self): self.lineEdit.insert("0") def btn_plus(self): self.lineEdit.insert("+") def btn_sub(self): self.lineEdit.insert("-") def btn_mul(self): self.lineEdit.insert("*") def btn_div(self): self.lineEdit.insert("/") def btnequal(self): text=self.lineEdit.text() self.lineEdit.insert("= %.2f" %(eval(text))) if __name__=='__main__': app=QApplication(sys.argv) win=Mywindow() win.pushButton_7.clicked.connect(win.btnClear_clicked()) win.pushButton.clicked.connect(win.btn1()) win.pushButton_2.clicked.connect(win.btn2()) win.pushButton_3.clicked.connect(win.btn3()) win.pushButton_4.clicked.connect(win.btn_plus()) win.pushButton_5.clicked.connect(win.btn4()) win.pushButton_6.clicked.connect(win.btn7()) win.pushButton_8.clicked.connect(win.btn5()) win.pushButton_9.clicked.connect(win.btn8()) win.pushButton_10.clicked.connect(win.btn0()) win.pushButton_11.clicked.connect(win.btn6()) win.pushButton_12.clicked.connect(win.btn9()) win.pushButton_13.clicked.connect(win.btnequal()) win.pushButton_14.clicked.connect(win.btn_sub()) win.pushButton_15.clicked.connect(win.btn_mul()) win.pushButton_16.clicked.connect(win.btn_div()) win.show() sys.exit(app.exec_())错在哪
时间: 2024-02-03 10:04:35 浏览: 103
PyQt5.QtWebEngine + JS 实现网页与Python的数据通信
5星 · 资源好评率100%
你忘记了在导入模块时使用逗号分隔,应该改为:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
from Calui1 import Ui_Form
class Mywindow(QWidget,Ui_Form):
def __init__(self):
super(Mywindow,self).__init__()
self.setupUi(self)
def btnClear_clicked(self):
self.lineEdit.clear()
def btn1(self):
self.lineEdit.insert("1")
def btn2(self):
self.lineEdit.insert("2")
def btn3(self):
self.lineEdit.insert("3")
def btn4(self):
self.lineEdit.insert("4")
def btn5(self):
self.lineEdit.insert("5")
def btn6(self):
self.lineEdit.insert("6")
def btn7(self):
self.lineEdit.insert("7")
def btn8(self):
self.lineEdit.insert("8")
def btn9(self):
self.lineEdit.insert("9")
def btn0(self):
self.lineEdit.insert("0")
def btn_plus(self):
self.lineEdit.insert("+")
def btn_sub(self):
self.lineEdit.insert("-")
def btn_mul(self):
self.lineEdit.insert("*")
def btn_div(self):
self.lineEdit.insert("/")
def btnequal(self):
text=self.lineEdit.text()
self.lineEdit.insert("= %.2f" %(eval(text)))
if __name__=='__main__':
app=QApplication(sys.argv)
win=Mywindow()
win.pushButton_7.clicked.connect(win.btnClear_clicked)
win.pushButton.clicked.connect(win.btn1)
win.pushButton_2.clicked.connect(win.btn2)
win.pushButton_3.clicked.connect(win.btn3)
win.pushButton_4.clicked.connect(win.btn_plus)
win.pushButton_5.clicked.connect(win.btn4)
win.pushButton_6.clicked.connect(win.btn7)
win.pushButton_8.clicked.connect(win.btn5)
win.pushButton_9.clicked.connect(win.btn8)
win.pushButton_10.clicked.connect(win.btn0)
win.pushButton_11.clicked.connect(win.btn6)
win.pushButton_12.clicked.connect(win.btn9)
win.pushButton_13.clicked.connect(win.btnequal)
win.pushButton_14.clicked.connect(win.btn_sub)
win.pushButton_15.clicked.connect(win.btn_mul)
win.pushButton_16.clicked.connect(win.btn_div)
win.show()
sys.exit(app.exec_())
```
阅读全文