VSCode + PYQT5 搭建图形化界面
阅读原文时间:2023年07月09日阅读:1

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:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages\pyqt5_tools\Qt\bin\designer.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_())

结果如下:

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章