安装PyQt5命令:
pip install PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple
安装Qt Designer命令:
pip install PyQt5-tools -i https://pypi.tuna.tsinghua.edu.cn/simple
在命令提示符中输入 designer即可运行。。
如果使用ubuntu安装,启动(运行)方式如下:
qt5-tools designer
运行界面:
可以进行简单的界面设计:
然后进行保存,会报存成.ui文件;
将ui文件转化成py文件:
在命令提示符中输入下面命令即可!
pyuic5 -o test.py test.ui
生成的test.py文件如下:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(120, 110, 93, 28))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "点我"))
添加代码即可运行py文件:
'''
Descripttion:
version:
Author: LiQiang
Date: 2021-01-24 13:35:36
LastEditTime: 2021-01-24 13:50:01
'''
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(120, 110, 93, 28))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
# self.buttonBox.accepted.connect(Dialog.accept)
# self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "点我"))
from PyQt5.QtWidgets import QMainWindow,QApplication,QPushButton
import sys
if __name__=='__main__':
app=QApplication(sys.argv)
mainwindow=QMainWindow()
ui=Ui_Dialog()
ui.setupUi(mainwindow)
mainwindow.show()
sys.exit(app.exec_())