VSCode + PYQT5 搭建图形化界面
Posted xcsg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VSCode + PYQT5 搭建图形化界面相关的知识,希望对你有一定的参考价值。
1,安装依赖
pip install -i https://mirrors.aliyun.com/pypi/simple/ PyQt5
pip install -i https://mirrors.aliyun.com/pypi/simple/ PyQt5-tools
2,找到designer 绘制ui界面程序
例:windows
C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagespyqt5_toolsQtindesigner.exe
绘制如下:
完事后保存 haha.ui
3,VSCode转化.ui文件为.py文件(安装PYQT Integration扩展)
右击haha.ui --- PYQT:Compile Form 会生成 Ui_haha.py 文件
然后调用UI类并运行py
import sys from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QApplication, QMainWindow class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(190, 200, 311, 81)) self.pushButton.setObjectName("pushButton") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton.setText(_translate("MainWindow", "你好")) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())
结果如下:
以上是关于VSCode + PYQT5 搭建图形化界面的主要内容,如果未能解决你的问题,请参考以下文章
PyQt5 图形界面 - Qt Designer独立安装包,仅需30M!python图像化界面绘制工具