在PyQt5中已经废弃了SINGAL()和SLOT()的调用方式
PyQt4下这种写法:
self.connect(self.lineedit, SIGNAL("returnPressed()"), self.updateUi)
换成PyQt5:
self.lineedit.returnPressed.connect(self.updateUi)
完整的代码如下:
from math import * from PyQt5.QtWidgets import QApplication,QDialog,QTextBrowser,QLineEdit,QVBoxLayout class Form(QDialog):#继承QDialog获得空白表单form def __init__(self, parent=None):#父类为None,变成顶级窗口 super(Form, self).__init__(parent)#初始化 self.browser = QTextBrowser()#文本框实例化 self.lineedit = QLineEdit("Type an expression and press Enter")#初始文本 self.lineedit.selectAll()#初始化是全选中 layout = QVBoxLayout() layout.addWidget(self.browser)#加进去窗口部件 layout.addWidget(self.lineedit)#加进去窗口部件 self.setLayout(layout)#布局进行设置 self.lineedit.setFocus()#设置光标位置在lineedit self.lineedit.returnPressed.connect(self.updateUi)#pytq5的新方法&