程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Run Python QTdesinger painting interface

編輯:Python

Using QTdesinger involves an interface. Roughly as follows

Select the saved ui file and open it with PyUic to view the code as follows

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'test.ui'## Created by: PyQt5 UI code generator 5.15.4## WARNING: Any manual changes made to this file will be lost when pyuic5 is# run again. Do not edit this file unless you know what you are doing.from PyQt5 import QtCore, QtGui, QtWidgetsclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(390, 398)self.lineEdit = QtWidgets.QLineEdit(Form)self.lineEdit.setGeometry(QtCore.QRect(70, 50, 231, 31))self.lineEdit.setObjectName("lineEdit")self.lineEdit_2 = QtWidgets.QLineEdit(Form)self.lineEdit_2.setGeometry(QtCore.QRect(70, 110, 231, 31))self.lineEdit_2.setObjectName("lineEdit_2")self.pushButton = QtWidgets.QPushButton(Form)self.pushButton.setGeometry(QtCore.QRect(70, 170, 231, 31))self.pushButton.setObjectName("pushButton")self.retranslateUi(Form)QtCore.QMetaObject.connectSlotsByName(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "Form"))self.lineEdit.setText(_translate("Form", "Account"))self.lineEdit_2.setText(_translate("Form", "Password"))self.pushButton.setText(_translate("Form", "Login"))

It is found that there is only one class in it. If you run the class, the interface you just drew will definitely not pop up

So you need to write some code to load this class, and then display the interface, because we may change the interface later

It is recommended to load this class in a method of the class.

The simple code is as follows

import sysfrom PyQt5 import QtWidgets# import this classfrom test import Ui_Form# Create an Application object, the sys.argv parameter is a list of parameters from the command line,app = QtWidgets.QApplication(sys.argv)# Create a widget component base classwindows = QtWidgets.QWidget()# instantiate the class of the ui interfaceui = Ui_Form()# Put the ui interface into the controlui.setupUi(windows)# interface displaywindows.show()# Execute the window trigger event in a loop, and exit without leaving garbage after the end. If you don't add it, the newly created widget component will flash by.sys.exit(app.exec_())

Run like this. This python file will load the interface drawn by qtdesinger.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved