使用Python pip安装PyQt5和PyQt5-tool
pip install PyQt5
pip install PyQt5-tools
在VS code中安装插件PYQT Integration
配置PYQT Integration
将安装好的pyuci5.exe和designer.exe路径填入PYQT Integration配置中:
对应的路径一般在Python的安装目录中(忘记python安装目录的可以在系统配置的path中查找),pyuci5.exe一般在Python\Python39\Scripts\pyuic5.exe
designer.exe一般在Python\Python39\site-packages\qt5_applications\Qt\bin\designer.exe
如果python目录中找不到,可以像我一样到用户目录下找:
C:\Users\27621\AppData\Roaming\Python\Python39\Scripts\pyuic5.exe
C:\Users\27621\AppData\Roaming\Python\Python39\site-packages\qt5_applications\Qt\bin\designer.exe
将路径填入PYQT Integration对应位置
创建工程并运行
创建helloworld目录并打开文件夹,右键选择PYQT:
New Form,此时会自动启用QT designer.exe。
选择Main Window并创建
添加Text Edit控件并修改内容为“Hello World!“ 保存文件为Helloworld.ui
右键ui文件并选择PYQT: Compile Form将.ui文件转化为.py文件:
新建python文件helloworld.py,并写入以下代码:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
import Ui_Helloworld
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_Helloworld.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
F5执行python文件,可以看到之前配置好的UI文件已经显示为程序界面: