安装pyqt5
pip install pyqt5_tools
pip install PyQt5
安装好以后,assistant和designer在C:\Program Files\Python36\Lib\site-packages\pyqt5-tools中
pyuic5在C:\Program Files\Python36\Scripts中
添加External Tools
在pycharm中添加外部工具方便使用
File-Settings-Tools-External Tools
参数按一下填写
QtDesigner
Program:C:\Program Files\Python36\Lib\site-packages\pyqt5-tools\designer.exe
Arguments:$FilePath$
Pyuic5
Program:C:\Program Files\Python36\python.exe
Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
(或者如此类型pyuic5.exe -o ui_Login.py Login.ui)
Working directory:$FileDir$
使用时选中要操作的文件,然后右键-External Tools-选择对应的工具即可
使用示例
使用QtDesigner设计UI
设计UI并保存,如:TestUI.ui
Pyuic 转换.ui为对应的.py
使用
此处使用了继承UI类的方法
UIPresenter.py
# coding=utf-8
# Python3.6
# UI Presenter
# Author:Why
# Date:2018.09.04
from PyQt5.QtWidgets import QMainWindow
import TestUI
class UIPresenter(QMainWindow, TestUI.Ui_MainWindow):
def __init__(self):
super(UIPresenter, self).__init__()
def __del__(self):
pass
Main.py
# coding=utf-8
# Python3.6
# Main(use Qt UI)
# Author:Why
# Date:2018.09.04
import sys
from PyQt5.QtWidgets import QApplication
import UIPresenter
if __name__ == '__main__':
app = QApplication(sys.argv)
ui_presenter = UIPresenter.UIPresenter()
ui_presenter.show()
sys.exit(app.exec())
运行Main.py即可显示设计的UI