赞
踩
arch -arm64 brew install pyqt@5 qt@5
cd /opt/homebrew/Cellar/pyqt@5
将库文件拷贝到Python环境中的site-packages目录下
代码测试
from PyQt5.QtWidgets import *
1.运行调试选择python解释器,我这里解释器是Python 3.7.11 (被命名为pytorch)
2.下载并安装PYQT Integration
(我是下载好过了,所以显示的是卸载)
3.配置pyqt integration
点击拓展设置
4.配置Pyuic:Cmd与Qtdesigner:Path路径
1.Pyuic:Cmd路径一般是在你安装的python环境下的 \Scripts\pyuic5.exe
2.Qtdesigner:Path
一般是在你安装的python环境下的\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
注意新版designer.exe不是在目录pyqt5_tools下而是qt5_applications目录下
四、创建pyqt文件,显示界面
在资源管理器空白处右键,然后点击PYQT:New Form就会出现qtdesigner界面了
QtDesigner
创建窗口,然后随便拖拽几个控件,点击保存到当前文件夹。
此时vscode出现ui文件
右键该文件并点击Compile Form
然后生成了UI_Mywin.py文件,可以看见是ui文件内容转成Python的。
你会发现单启动这个文件是没有效果的,我们如何启动这个界面呢?
新建一个python文件,让你的类继承你写的界面类就行了。(我们一般不在UI_Mywin.py中写启动类,因为将逻辑业务和前端代码分离是比较友好的)
import sys
from PyQt5.QtWidgets import QMainWindow,QApplication,QWidget
from Ui_Mywin import Ui_MainWindow #导入你写的界面类
class MyMainWindow(QMainWindow,Ui_MainWindow): #这里也要记得改
def __init__(self,parent =None):
super(MyMainWindow,self).__init__(parent)
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWin = MyMainWindow()
myWin.show()
sys.exit(app.exec_())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。