一、 安裝PyQt相關(guān)包
pip install PyQt5
pip install PyQt5-tools
在個(gè)人python環(huán)境中安裝PyQt相關(guān)包,如圖所示:
二、 VSCode安裝PyQt插件
在VSCode上搜素PyQt,安裝PYQT Integration插件,如圖所示:
點(diǎn)擊擴(kuò)展設(shè)置,如圖所示:
配置Pyuic:Cmd與Qtdesigner:Path路徑,如圖所示:
- Pyuic:Cmd路徑在D:\Users\wuhailei\AppData\Local\anaconda3\envs\WHL\Scripts\pyuic5.exe
- Qtdesigner:Path路徑在D:\Users\wuhailei\AppData\Local\anaconda3\envs\WHL\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
三、 創(chuàng)建PyQt
右鍵,然后點(diǎn)擊PYQT:New Form,如圖所示:
Qt Designer 界面如下:
創(chuàng)建窗口,然后拖拽幾個(gè)控件,點(diǎn)擊保存,如圖所示:
然后VSCode出現(xiàn)ui文件,如圖所示:
右鍵該文件,并點(diǎn)擊PYQT:Compile Form,如圖所示:
生成了Ui_untitled.py文件,是ui文件內(nèi)容轉(zhuǎn)成了Python,如圖所示:
新建main.py文件,輸入如下代碼:
import sys
from PyQt5.QtWidgets import QMainWindow,QApplication
from Ui_untitled import Ui_Dialog
class MyWindow(QMainWindow,Ui_Dialog):
def __init__(self,parent =None):
super(MyWindow,self).__init__(parent)
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWin = MyWindow()
myWin.show()
sys.exit(app.exec_())
如圖所示:
運(yùn)行即可出現(xiàn)剛剛設(shè)計(jì)的GUI,如圖所示:
接下來就可以愉快的開啟PyQt設(shè)計(jì)UI界面之路了
希望本文對大家有幫助,上文若有不妥之處,歡迎指正文章來源:http://www.zghlxwxcb.cn/news/detail-730168.html
分享決定高度,學(xué)習(xí)拉開差距文章來源地址http://www.zghlxwxcb.cn/news/detail-730168.html
到了這里,關(guān)于手把手一起在VSCode上配置PyQt5的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!