赞
踩
环境搭建
python环境
安装目录 : D:Anaconda3
添加以下目录到环境变量
D:Anaconda3
D:Anaconda3condabin
D:Anaconda3Scripts
安装PyQt5,pyqt5-tools,PyQt5-stubs
pip install PyQt5==5.12.1.0
pip install pyqt5-tools==5.11.3.1.4
pip install PyQt5-stubs==5.12.1.0
安装Python IDE
eric6(可选)
解压后安装 : python install.py install
使用智能IDE : PyCharm
配置PyQt5
打开PyCharm
Python Interpreter选择D:Anaconda3python.exe
打开SettingsToolsExternal Tools
新建分组Qt5
Name : Qt_Designer
Group : Qt5
Programe : D:Anaconda3Libsite-packagespyqt5_toolsdesigner.exe
Working directory : $FileDir$
Name : Qt_Pyuic
Group : Qt5
Programe : D:Anaconda3Scriptspyuic5.exe
Arguments : $FileName$ -o $FileNameWithoutExtension$.py
Working directory : $FileDir$
Name : Qt_Pyrcc
Group : Qt5
Programe : D:Anaconda3Scriptspyrcc5.exe
Arguments : $FileName$ -o $FileNameWithoutExtension$_rc.py
Working directory : $FileDir$
新建项目
打开ToolsQt5Qt_Designer,新建文档,拖动一些控件,保存到你的项目路径,这边文档名为project.ui
关闭Qt_Designer,项目多了project.ui,右键Qt5Qt_Pyuic,将project.ui转化成project.py
我的project.py内容如下:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(480, 422)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(160, 80, 93, 28))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(160, 190, 141, 71))
self.label.setObjectName("label")
self.retranslateUi(Form)
self.pushButton.clicked.connect(self.label.clear)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.label.setText(_translate("Form", "TextLabel"))
新建一个python测试文档 : qt_test.py,内容如下:
import sys
from project import Ui_Form
from PyQt5.QtWidgets import QApplication, QMainWindow
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_Form()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
PyCharm右上角,选择Edit Configurations
添加Python
Script path : 你的项目qt_test.py
Python Interpreter : D:Anaconda3python.exe
Working directory : 你的项目路径
到此可以正常运行使用了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。