#python pyqt#
????????python:3.11.6
????????pycharm:PyCharm Community Edition 2023.2.5
? ? ? ? pyqt6
python安裝
官網下載:Python Releases for Windows | Python.org
??
pycharm社區版安裝
官網地址:Download PyCharm: Python IDE for Professional Developers by JetBrains
?
pip設置國內源
?安裝完成后如果使用pip安裝第三方庫會很慢,設置國內源。國內源通常使用的有下面5個
豆瓣(douban) http://pypi.douban.com/simple/?
阿里云 http://mirrors.aliyun.com/pypi/simple/?
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/?騰訊云 http://mirrors.cloud.tencent.com/pypi/simple
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
設置清華源指令
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
?win +X ,選擇《命令提示符管理員》,輸入設定清華源指令
安裝Pyqt6 與PyQt6-tools
?pip install PyQt6 PyQt6-tools
創建新項目?
注:
????????由于剛才在命令行下安裝第三方庫到Python311\Scripts,新建香項目時可以勾選Inherit global site-packages,創建項目時會拷貝到當前項目
Inherit global site-packages ,Python311\Scripts的安裝第三方庫會拷貝添加到當前項目
make available to all projects,當前項目安裝的第三方庫會拷貝添加到Python311\Scripts
? ? ? ? 當我們需要創建一個干凈的項目,就可以不夠選這兩個選項
?設置外部工具
Name:QtDesignerGroup:PYQT6Program:D:\Program Files\Python311\Lib\site-packages\qt6_applications\Qt\bin\designer.exe(自己安裝的python路徑)Arguments:Working directory:$FileDir$
Name:PyuicGroup:PYQT6Program:D:\Program Files\Python311\Scripts\pyuic6.exe(自己安裝的python路徑)Arguments:$FileName$ -o $FileNameWithoutExtension$.pyWorking directory:$ProjectFileDir$
?QtDesigner編輯UI界面
??Pyuic將UI文件轉換為py文件
?
?
?創建main.py
?
??
import sys
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.uic.Compiler.qtproxies import QtWidgetsfrom untitled import Ui_Form class MyMainForm(QWidget, Ui_Form):def __init__(self):super(MyMainForm, self).__init__()self.setupUi(self)# Press the green button in the gutter to run the script.
if __name__ == '__main__':app = QApplication(sys.argv)myw = MyMainForm()myw.show()sys.exit(app.exec())
執行main.py?
?
?
?
彈出如下警告,忽視該警告;也可以用python 3.9,python3.9執行將不會出現下面警告
DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() insteadsuper(MyMainForm, self).__init__()?
?