今天,心血来潮配置了一下PyCharm+PyQt5,按照别人配置的方法配置了好几次,出现了各种问题,总之,都是Arguements和Working directiory的问题,所以记录一下,防止大家踩坑。
步骤:
1、安装PyQt5
pip install PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple
2、安装PyQt5-tools
pip install PyQt5-tools -i https://pypi.tuna.tsinghua.edu.cn/simple
5、打开PyCharm,在External Tools里面添加Qt Designer和pyUIC
6、配置Qt Designer
Program选择你自己的designer.exe路径
Working directiory:$ProjectFileDir$
6、配置pyUIC
Program选择你自己的piuic5.exe路径
Arguments:$FileName$ -o $FileNameWithoutExtension$.py
Working directiory:$FileDir$
7、打开Qt Designer
8、创建Widget窗口
9、随便拖个控件出来
10、保存
11、保存之后会生成一个ui文件
12、选择该文件,并用pyUIC转换成.py文件
13、修改test.py文件(实例化一个窗口出来并显示),并运行
修改后的代码:
# -*- 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, QtWidgets
import sys
class Ui_Form(QtWidgets.QWidget):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(708, 396)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(290, 160, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "Hello"))
app=QtWidgets.QApplication(sys.argv)
windows=Ui_Form()
windows.setupUi(windows)
windows.retranslateUi(windows)
windows.show()
sys.exit(app.exec())