[Python][原创]pycharm+anaconda3+Pyqt5的QtDesign、pyuic、pyrcc配置
实验环境:
Anaconda 2019.10 for Windows Installer
Python 3.7 version
Pycharm 2019.01
PyQt5
Anaconda3里面可以直接安装PyQt5安装后已经有tools工具了,具体操作
安装后我们在Pycharm配置QtDesign,打开Pycharm-File-Setting-External Tools-点击+号添加如下配置:
Name:QtDesigner
Group:Qt
Programs:D:\ProgramData\Anaconda3\Library\bin\designer.exe(这里是各位自己的designer路径,之前所看到的)
Working directory:$ProjectFileDir$
Pyuic的配置如下:
Name:pyuic
Group:Qt
Program:D:\ProgramData\Anaconda3\python.exe(各位自己的python路径)
Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
Working directory:$FileDir$
注意:这样设置ui转换成py文件没有__name__==”__main__”如果你想自动生成可以这么搞:
Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py -x
回到PyCharm,Tools—>Qt—>QtDesigner,点击即可打开designer
Pyrcc配置:
Anaconda安装的pyqt是没有pyrcc的,需要在dos窗口自己安装一下:
pip install pyqt5_tools
安装完以后再Annaconda目录搜素pyrcc可以找到:
配置参数如下:
Name:pyrcc
Group:Qt
Program:D:\ProgramData\Anaconda3\Scripts\pyrcc5.exe(各位自己的python路径)
Arguments:$FileName$ -o $FileNameWithoutExtension$_rc.py
Working directory:$FileDir$
至此就全部配置好了。
示例:我随便在Qt界面拖放一个pushbutton按钮,然后就转成py文件,稍微改动就可以跑起来:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(560, 403)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(120, 110, 261, 71))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
self.pushButton.clicked.connect(Form.btn_click)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "点我"))
class Form1(QtWidgets.QWidget):
def __init__(self):
super().__init__()
def btn_click(self):
print('11111111111')
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = Form1()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
- 点赞
- 收藏
- 关注作者
评论(0)