PyCharm搭建PyQt5开发环境
win7
PyCharm 2018.1.4
python 3.6.5
1.安装PyQt5
打开cmd运行安装指令(已经安装了python)
2.PyCharm环境配置
打开PyCharm,执行快捷键ctrl+alt+s
打开设置界面,点开external tools
2.1 添加QtDesigner
2.2 添加PyUIC
Arguments:
-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
2.3 添加Pyrcc
Arguments:
$FileName$ -o $FileNameWithoutExtension$_rc.py
2.4 添加assistant
2.5 添加linguist
3.测试
3.1 新建项目
3.2 创建一个ui
这里选择一个MainWindow
在窗口上拖进一个日历控件
运行快捷键ctrl+s
保存ui文件
在PyCharm中可以看到生成的ui文件
3.2 使用PyUIC将.ui文件转换为.py文件
3.4 编写main函数
运行快捷键alt+insert
打开新建文件窗口
编写程序调用窗口
运行快捷键alt+shift+F10
启动程序
运行效果
程序
import sys
import testui
from PyQt5.QtWidgets import QApplication, QMainWindow
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = testui.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
4.教程
https://pythonspot.com/en/pyqt5/
https://www.bookstack.cn/read/PyQt5-Chinese-tutoral/README.md
帮助文档:
https://doc.qt.io/qt-5/classes.html
书籍:
《PyQt5快速开发与实战》python3.x和PyQt5
《Python Qt GUI快速编程——PyQt编程指南》python2.x和PyQt4开发