我是pyqt5的新手。我使用qt设计器制作了两个窗口,并使用pyuic将它们转换为python代码。单击时,我还连接了注册按钮以显示注册表单窗口。但是,现在当我运行程序并单击“注册”按钮时,“注册”窗口中仅显示“提交”按钮,其余部分完全为空。
这是带有主窗口的文件
from PyQt5 import QtCore, QtGui, QtWidgets
from regform import Ui_cnum
class Ui_Form(object):
def add(self):
self.window = QtWidgets.QMainWindow()
self.ui= Ui_cnum()
self.ui.setupUi(self.window)
self.window.show()
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(187, 167)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.register_2 = QtWidgets.QPushButton(Form)
self.register_2.setObjectName("register_2")
self.register_2.clicked.connect(self.add)
self.horizontalLayout.addWidget(self.register_2)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem2)
self.update = QtWidgets.QPushButton(Form)
self.update.setObjectName("update")
self.horizontalLayout_2.addWidget(self.update)
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem3)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem4)
self.remove = QtWidgets.QPushButton(Form)
self.remove.setObjectName("remove")
self.horizontalLayout_3.addWidget(self.remove)
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem5)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem6)
self.list = QtWidgets.QPushButton(Form)
self.list.setObjectName("list")
self.horizontalLayout_4.addWidget(self.list)
spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem7)
self.verticalLayout.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem8)
self.verify = QtWidgets.QPushButton(Form)
self.verify.setObjectName("verify")
self.horizontalLayout_5.addWidget(self.verify)
spacerItem9 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem9)
self.verticalLayout.addLayout(self.horizontalLayout_5)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "User Menu"))
self.register_2.setText(_translate("Form", "Register"))
self.update.setText(_translate("Form", "Update"))
self.remove.setText(_translate("Form", "Remove"))
self.list.setText(_translate("Form", "List"))
self.verify.setText(_translate("Form", "Verify"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
这是注册表格窗口中的文件
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_cnum(object):
def setupUi(self, cnum):
cnum.setObjectName("cnum")
cnum.resize(400, 300)
self.verticalLayout = QtWidgets.QVBoxLayout(cnum)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(cnum)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.fname = QtWidgets.QLineEdit(cnum)
self.fname.setObjectName("fname")
self.horizontalLayout.addWidget(self.fname)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(cnum)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem1)
self.lname = QtWidgets.QLineEdit(cnum)
self.lname.setObjectName("lname")
self.horizontalLayout_2.addWidget(self.lname)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_3 = QtWidgets.QLabel(cnum)
self.label_3.setObjectName("label_3")
self.horizontalLayout_3.addWidget(self.label_3)
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem2)
self.cnic = QtWidgets.QLineEdit(cnum)
self.cnic.setObjectName("cnic")
self.horizontalLayout_3.addWidget(self.cnic)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_4 = QtWidgets.QLabel(cnum)
self.label_4.setObjectName("label_4")
self.horizontalLayout_4.addWidget(self.label_4)
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem3)
self.regno = QtWidgets.QLineEdit(cnum)
self.regno.setObjectName("regno")
self.horizontalLayout_4.addWidget(self.regno)
self.verticalLayout.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.label_5 = QtWidgets.QLabel(cnum)
self.label_5.setObjectName("label_5")
self.horizontalLayout_5.addWidget(self.label_5)
spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem4)
self.eno = QtWidgets.QLineEdit(cnum)
self.eno.setObjectName("eno")
self.horizontalLayout_5.addWidget(self.eno)
self.verticalLayout.addLayout(self.horizontalLayout_5)
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.label_6 = QtWidgets.QLabel(cnum)
self.label_6.setObjectName("label_6")
self.horizontalLayout_6.addWidget(self.label_6)
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem5)
self.cno = QtWidgets.QLineEdit(cnum)
self.cno.setObjectName("cno")
self.horizontalLayout_6.addWidget(self.cno)
self.verticalLayout.addLayout(self.horizontalLayout_6)
self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.label_7 = QtWidgets.QLabel(cnum)
self.label_7.setObjectName("label_7")
self.horizontalLayout_7.addWidget(self.label_7)
spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_7.addItem(spacerItem6)
self.papa = QtWidgets.QLineEdit(cnum)
self.papa.setObjectName("papa")
self.horizontalLayout_7.addWidget(self.papa)
self.verticalLayout.addLayout(self.horizontalLayout_7)
self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_8.addItem(spacerItem7)
self.submit = QtWidgets.QPushButton(cnum)
self.submit.setObjectName("submit")
self.horizontalLayout_8.addWidget(self.submit)
spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_8.addItem(spacerItem8)
self.verticalLayout.addLayout(self.horizontalLayout_8)
self.retranslateUi(cnum)
QtCore.QMetaObject.connectSlotsByName(cnum)
def retranslateUi(self, cnum):
_translate = QtCore.QCoreApplication.translate
cnum.setWindowTitle(_translate("cnum", "Registration Form"))
self.label.setText(_translate("cnum", "First Name"))
self.label_2.setText(_translate("cnum", "Last Name"))
self.label_3.setText(_translate("cnum", "CNIC"))
self.label_4.setText(_translate("cnum", "Registration Number"))
self.label_5.setText(_translate("cnum", "Engine Number"))
self.label_6.setText(_translate("cnum", "Chassis Number"))
self.label_7.setText(_translate("cnum", "Father\'s Name"))
self.submit.setText(_translate("cnum", "Submit"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
cnum = QtWidgets.QWidget()
ui = Ui_cnum()
ui.setupUi(cnum)
cnum.show()
sys.exit(app.exec_())