VSCode插件安装
安装Python插件
安装PySide6插件
PySide6安装
pip install PySide6 -i https://pypi.mirrors.ustc.edu.cn/simple/
注:使用第三方源安装,提高下载速度
PySide6配置
进入配置界面 参数配置
"python.defaultInterpreterPath": "C:\\Python39\\python.exe",
"qtForPython.lupdate.liveExecution": true,
"qtForPython.uic.path": "C:\\Python39\\Lib\\site-packages\\PySide6\\uic.exe ",
"qtForPython.designer.path": "C:\\Python39\\Lib\\site-packages\\PySide6\\designer.exe",
"qtForPython.rcc.path": "C:\\Python39\\Lib\\site-packages\\PySide6\\rcc.exe",
"qtForPython.lupdate.path": "C:\\Python39\\Lib\\site-packages\\PySide6\\lupdate.exe",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"qtForPython.uic.args": [
"-g python -o \"${workspaceFolder}${pathSeparator}ui${pathSeparator}uic${pathSeparator}${fileBasenameNoExtension}.py\""
],
注:UI转换为Python文件的路径:ui\uic
VSCode创建UI文件
测试代码
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QDialog
from PySide6.QtCore import QFile
sys.path.append("ui\\uic")
from test_ui import Ui_MainWindow
class QMainWindow(QMainWindow):
def __init__(self):
super(QMainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = QMainWindow()
window.show()
sys.exit(app.exec_())
运行测试
代码执行 运行结果
参考链接
- VS code 配置 PySide6的UI开发环境
- PySide6+VSCode环境搭建
- PIP安装出现“NO MODULE NAMED 'PIP”
|