.ui界面是:
生成的.py是:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'html_to_doors.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Mainform(object):
def setupUi(self, Mainform):
Mainform.setObjectName("Mainform")
Mainform.resize(1430, 817)
self.Title = QtWidgets.QLabel(Mainform)
self.Title.setGeometry(QtCore.QRect(380, 20, 751, 30))
font = QtGui.QFont()
font.setFamily("仿宋")
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.Title.setFont(font)
self.Title.setObjectName("Title")
self.openfile = QtWidgets.QPushButton(Mainform)
self.openfile.setGeometry(QtCore.QRect(1200, 90, 121, 33))
font = QtGui.QFont()
font.setPointSize(12)
self.openfile.setFont(font)
self.openfile.setObjectName("openfile")
self.filepath = QtWidgets.QLineEdit(Mainform)
self.filepath.setGeometry(QtCore.QRect(40, 90, 1121, 31))
self.filepath.setObjectName("filepath")
self.doors_text = QtWidgets.QTextEdit(Mainform)
self.doors_text.setGeometry(QtCore.QRect(30, 240, 661, 531))
self.doors_text.setObjectName("doors_text")
self.version = QtWidgets.QLabel(Mainform)
self.version.setGeometry(QtCore.QRect(1060, 40, 55, 16))
font = QtGui.QFont()
font.setPointSize(10)
font.setItalic(True)
self.version.setFont(font)
self.version.setObjectName("version")
self.capl_text = QtWidgets.QTextEdit(Mainform)
self.capl_text.setGeometry(QtCore.QRect(730, 240, 661, 531))
self.capl_text.setObjectName("capl_text")
self.start = QtWidgets.QPushButton(Mainform)
self.start.setGeometry(QtCore.QRect(1200, 150, 121, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.start.setFont(font)
self.start.setObjectName("start")
self.doors = QtWidgets.QLabel(Mainform)
self.doors.setGeometry(QtCore.QRect(50, 200, 551, 31))
font = QtGui.QFont()
font.setFamily("仿宋")
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.doors.setFont(font)
self.doors.setObjectName("doors")
self.capl = QtWidgets.QLabel(Mainform)
self.capl.setGeometry(QtCore.QRect(740, 200, 371, 30))
font = QtGui.QFont()
font.setFamily("仿宋")
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.capl.setFont(font)
self.capl.setObjectName("capl")
self.bottom = QtWidgets.QLabel(Mainform)
self.bottom.setGeometry(QtCore.QRect(640, 780, 161, 30))
font = QtGui.QFont()
font.setFamily("MS Shell Dlg 2")
font.setPointSize(10)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.bottom.setFont(font)
self.bottom.setObjectName("bottom")
self.retranslateUi(Mainform)
QtCore.QMetaObject.connectSlotsByName(Mainform)
def retranslateUi(self, Mainform):
_translate = QtCore.QCoreApplication.translate
Mainform.setWindowTitle(_translate("Mainform", "Dialog"))
self.Title.setText(_translate("Mainform", "HTML Steps to Doors Test Specification Tool"))
self.openfile.setText(_translate("Mainform", "OpenFile"))
self.version.setText(_translate("Mainform", "V1.0"))
self.start.setText(_translate("Mainform", "Start"))
self.doors.setText(_translate("Mainform", "Doors Test Specification:"))
self.capl.setText(_translate("Mainform", "Capl Test Purpose:"))
self.bottom.setText(_translate("Mainform", "©2020 veoneer"))
更改后为:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'html_to_doors.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtWidgets import QApplication
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setupUi(self)
self.retranslateUi(self)
def setupUi(self, Mainform):
Mainform.setObjectName("MainWindow")
Mainform.resize(1430, 817)
self.Title = QtWidgets.QLabel(Mainform)
self.Title.setGeometry(QtCore.QRect(380, 20, 751, 30))
font = QtGui.QFont()
font.setFamily("仿宋")
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.Title.setFont(font)
self.Title.setObjectName("Title")
self.openfile = QtWidgets.QPushButton(Mainform)
self.openfile.setGeometry(QtCore.QRect(1200, 90, 121, 33))
font = QtGui.QFont()
font.setPointSize(12)
self.openfile.setFont(font)
self.openfile.setObjectName("openfile")
self.filepath = QtWidgets.QLineEdit(Mainform)
self.filepath.setGeometry(QtCore.QRect(40, 90, 1121, 31))
self.filepath.setObjectName("filepath")
self.doors_text = QtWidgets.QTextEdit(Mainform)
self.doors_text.setGeometry(QtCore.QRect(30, 240, 661, 531))
self.doors_text.setObjectName("doors_text")
self.version = QtWidgets.QLabel(Mainform)
self.version.setGeometry(QtCore.QRect(1060, 40, 55, 16))
font = QtGui.QFont()
font.setPointSize(10)
font.setItalic(True)
self.version.setFont(font)
self.version.setObjectName("version")
self.capl_text = QtWidgets.QTextEdit(Mainform)
self.capl_text.setGeometry(QtCore.QRect(730, 240, 661, 531))
self.capl_text.setObjectName("capl_text")
self.start = QtWidgets.QPushButton(Mainform)
self.start.setGeometry(QtCore.QRect(1200, 150, 121, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.start.setFont(font)
self.start.setObjectName("start")
self.doors = QtWidgets.QLabel(Mainform)
self.doors.setGeometry(QtCore.QRect(50, 200, 551, 31))
font = QtGui.QFont()
font.setFamily("仿宋")
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.doors.setFont(font)
self.doors.setObjectName("doors")
self.capl = QtWidgets.QLabel(Mainform)
self.capl.setGeometry(QtCore.QRect(740, 200, 371, 30))
font = QtGui.QFont()
font.setFamily("仿宋")
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.capl.setFont(font)
self.capl.setObjectName("capl")
self.bottom = QtWidgets.QLabel(Mainform)
self.bottom.setGeometry(QtCore.QRect(640, 780, 161, 30))
font = QtGui.QFont()
font.setFamily("MS Shell Dlg 2")
font.setPointSize(10)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.bottom.setFont(font)
self.bottom.setObjectName("bottom")
self.retranslateUi(Mainform)
QtCore.QMetaObject.connectSlotsByName(Mainform)
def retranslateUi(self, Mainform):
_translate = QtCore.QCoreApplication.translate
Mainform.setWindowTitle(_translate("Mainform", "Dialog"))
self.Title.setText(_translate("Mainform", "HTML Steps to Doors Test Specification Tool"))
self.openfile.setText(_translate("Mainform", "OpenFile"))
self.version.setText(_translate("Mainform", "V1.0"))
self.start.setText(_translate("Mainform", "Start"))
self.doors.setText(_translate("Mainform", "Doors Test Specification:"))
self.capl.setText(_translate("Mainform", "Capl Test Purpose:"))
self.bottom.setText(_translate("Mainform", "©2020 veoneer"))
if __name__ == '__main__':
app=QApplication(sys.argv)
ex=MainWindow()
ex.show()
sys.exit(app.exec_())
修改的地方是:
import sys
from PyQt5.QtWidgets import QApplication
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setupUi(self)
self.retranslateUi(self)
if __name__ == '__main__':
app=QApplication(sys.argv)
ex=MainWindow()
ex.show()
sys.exit(app.exec_())