本文主要是介绍python之pyqt专栏1-环境搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#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__()
这篇关于python之pyqt专栏1-环境搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!