赞
踩
pip install pyside6
要配置的参数一共有五个,包括
在扩展页面点击 扩展设置 。进入扩展设置
点击 在setting.json中编辑
把下面的粘贴到末尾。然后开始替换前面三个的路径(下面为null的部分)
"qtForPython.designer.path": null,
"qtForPython.rcc.path": null,
"qtForPython.uic.path": null,
"qtForPython.uic.args": [
"-o ${fileDirname}${pathSeparator}Ui_${fileBasenameNoExtension}.py"
],
"qtForPython.rcc.args": [
"-o ${fileDirname}${pathSeparator}rc_${fileBasenameNoExtension}.py"
],
python pip show pyside6
查看pyside6的安装路径这里Designer.app可以直接打开,完成设计后将ui文件编译为py文件,然后使用python导入,效果一致
在vs code左侧资源管理器,右键点击最下面的 New Form
出现这些窗口表示Designer 配置成功
绘制一个窗口。然后对这个ui文件点击 Compile Form into Qt for Python File
出现了Ui_test.py表示编译成功。
安装结束
这里给一份我的代码以供大家测试
import sys from PySide6 import QtCore, QtWidgets, QtGui import Ui_test class TestWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() ui = Ui_test.Ui_MainWindow() ui.setupUi(self) @QtCore.Slot()#槽函数用它装饰 def login(self): #在Qt Designer中为登录按钮命名的槽函数; print("你点击了登录") if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) widget = TestWindow() widget.show() sys.exit(app.exec())
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>800</width> <height>600</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>240</x> <y>180</y> <width>58</width> <height>16</height> </rect> </property> <property name="text"> <string>用户名:</string> </property> </widget> <widget class="QTextEdit" name="textEdit"> <property name="geometry"> <rect> <x>290</x> <y>180</y> <width>211</width> <height>21</height> </rect> </property> </widget> <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> <x>240</x> <y>220</y> <width>31</width> <height>16</height> </rect> </property> <property name="text"> <string>密码:</string> </property> </widget> <widget class="QTextEdit" name="textEdit_2"> <property name="geometry"> <rect> <x>293</x> <y>220</y> <width>211</width> <height>21</height> </rect> </property> </widget> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>330</x> <y>270</y> <width>100</width> <height>32</height> </rect> </property> <property name="text"> <string>login</string> </property> </widget> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections> <connection> <sender>pushButton</sender> <signal>clicked()</signal> <receiver>MainWindow</receiver> <slot>login()</slot> <hints> <hint type="sourcelabel"> <x>409</x> <y>283</y> </hint> <hint type="destinationlabel"> <x>515</x> <y>340</y> </hint> </hints> </connection> </connections> <slots> <slot>login()</slot> </slots> </ui>
# -*- coding: utf-8 -*- ################################################################################ ## Form generated from reading UI file 'test.ui' ## ## Created by: Qt User Interface Compiler version 6.3.1 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt) from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) from PySide6.QtWidgets import (QApplication, QLabel, QMainWindow, QPushButton, QSizePolicy, QStatusBar, QTextEdit, QWidget) class Ui_MainWindow(object): def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(800, 600) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.label = QLabel(self.centralwidget) self.label.setObjectName(u"label") self.label.setGeometry(QRect(240, 180, 58, 16)) self.textEdit = QTextEdit(self.centralwidget) self.textEdit.setObjectName(u"textEdit") self.textEdit.setGeometry(QRect(290, 180, 211, 21)) self.label_2 = QLabel(self.centralwidget) self.label_2.setObjectName(u"label_2") self.label_2.setGeometry(QRect(240, 220, 31, 16)) self.textEdit_2 = QTextEdit(self.centralwidget) self.textEdit_2.setObjectName(u"textEdit_2") self.textEdit_2.setGeometry(QRect(293, 220, 211, 21)) self.pushButton = QPushButton(self.centralwidget) self.pushButton.setObjectName(u"pushButton") self.pushButton.setGeometry(QRect(330, 270, 100, 32)) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName(u"statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) self.pushButton.clicked.connect(MainWindow.login) QMetaObject.connectSlotsByName(MainWindow) # setupUi def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) self.label.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u540d:", None)) self.label_2.setText(QCoreApplication.translate("MainWindow", u"\u5bc6\u7801\uff1a", None)) self.pushButton.setText(QCoreApplication.translate("MainWindow", u"login", None)) # retranslateUi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。