当前位置:网站首页>PyQt5学习一(环境搭建)
PyQt5学习一(环境搭建)
2022-07-29 20:29:00 【qq_34981】
1.工具
Python
PyCharm
PyQt5模块
PyQt5模块可以在PyCharm软件中直接进行安装。
2.PyQt5模块安装
在PyCharm工具的下发Terminal中输入如下两条命令进行安装
pip install PyQt5
pip install PyQt5-tools
3.配置QtDesigner、PyUIC、PyRCC
1.在pycharm中点击“file” -> "Settings"选项

2.在弹出的对话框中选择"Tools" -> "External Tools"

3.点击“+”,在弹出的对话框中设置QtDesigner
Name:QtDesigner
Program:designer.exe所在的路径
Working directory:$ProjectFileDir$

4.点击“+”,在弹出的对话框中设置PyUIC
Name:PyUIC
Program:填入python.exe的路径
Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
Working directory:$FileDir$

5.点击“+”,在弹出的对话框中设置PyRCC
Name:PyRCC
Program:填入pyrcc5.exe的路径
Arguments:$FileName$ -o $FileNameWithoutExtension$_rc.py
Working directory:$FileDir$

4.编写界面
1.点击PyCharm菜单栏的“Tools” ->“External Tools” -> "QtDesigner"。来运行QtDesigner。


2.选择“Dialog without Button”来创建一个空白页

3.在左侧菜单栏中选择“Text Browser”,并拖拉到对话框中。“双击”自己添加的Browser,在其中输入"Hello Wrold"。

4.“Ctrl+s”保存,此时会在自己的工程目录下看到自己保存的文件。

5.在"test.ui"上右键,在“External Tools”中选择“PyUIC”。
,
6.此时在工程目录下会出现“test.py”的文件。如果没有出现,可以在工程目录上右键,选择“Reload from Disk”来重新加载文件。此时"test.py"文件就会出现了。


5.编译并运行UI
在另外一个文件中导入如下代码。
import sys
import test
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QInputDialog, QLineEdit, QDialog
if __name__ == '__main__':
# 创建QApplication类的实例
myapp = QApplication(sys.argv)
# 创建一个对话框
myDlg = QDialog()
# 创建自己绘制的对话框
myUI = test.Ui_Dialog()
# 将对话框依附于主窗体
myUI.setupUi(myDlg)
# 显示窗口
myDlg.show()
# 进入程序的主循环,并通过exit函数确保主循环安全结束(该释放的资源一定要释放)
sys.exit(myapp.exec_())附上可能出现的错误以及解决方法。(主要是Pyqt4升级到pyqt5遇到的)
1. NameError: name 'QApplication' is not defined
from PyQt5.QtWidgets import QApplication2. NameError: name 'QLabel' is not defined
from PyQt5.QtWidgets import *3. NameError: name 'QDialog' is not defined
from PyQt5.QtWidgets import QInputDialog, QLineEdit, QDialog运行代码,则显示出自己绘制的UI

边栏推荐
- Panorama Tutorial丨How to shoot sunrise and sunset scenes in VR panoramic shooting?
- JS实现百叶窗特效
- 如何进入董事会:给CIO的十条建议
- The cornerstone of distributed: reliability - What a tangled web we weave
- Internship: use easypoi to import and export excel table data
- 378. The Kth Smallest Element in an Ordered Matrix
- WeChat Mini Program 31 Subcontracting Mechanism
- conda虚拟环境 | install 与 list 问题
- Related phrases include usage and collocation (include)
- 无文件落地免杀的初尝试思考(上)
猜你喜欢

MSNs-SS-siRNA二氧化硅-二硫键-核酸RNA|HA-SS-siRNA,hyaluronic acid透明质酸修饰RNA(RNA修饰剂)

写出优雅的Kotlin代码:聊聊我认为的 “Kotlinic“

OneNote 教程,如何在 OneNote 中做笔记?

RNA修饰技术介绍|介孔二氧化硅纳米颗粒(MSN)搭载的微小RNA-24(miR-24)纳米载体复合物

Dry goods!Cooperative Balance in Federated Learning

ALBERT:A Lite BERT for Self-supervised Learning of Language Representations

VSCode配置终端为系统命令行
![LeetCode 593 有效的正方形[数学] HERODING的LeetCode之路](/img/c2/34624c9c7693ba40d0b3724c0db611.png)
LeetCode 593 有效的正方形[数学] HERODING的LeetCode之路

LOG4J 学习
基于PaddleSpeech搭建个人语音听写服务
随机推荐
OneNote tutorial, how to take notes in OneNote?
LeetCode 593 Valid Squares [Math] HERODING's Road to LeetCode
Baidu internship students late night fun: originally giant is this kind of life
MySQL Data Query - Union Query
SAP ABAP OData 服务 Data Provider Class 的 GET_ENTITYSET 方法实现指南试读版
Come in now!!!Take you to know the basic data types of C language
第二好PyTorch新手课程;论文写作指南;使用µGo语言开发迷你编译器;超高效使用Transformer的扩展库;前沿论文 | ShowMeAI资讯日报
微信小程序 31 分包机制
最小jvm源码分析
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
诺氟沙星-DNA复合物|半乳糖化脂质体-聚阳离子-DNA复合物|注意事项
QT安装、创建项目与调试,在VS中的使用:手把手教程
双功能RGD-TAT修饰DNA纳米胶束|聚苯胺纳米线修饰DNA(PAINW/DNA)
RedisJson 横空出世!
Permutations of a small feat: cantor
Cobaltstrike and BurpSuite desktop shortcut configuration
R language for airbnb data nlp text mining, geography, word cloud visualization, regression GAM model, cross-validation analysis
What are the software development modes (software engineering development mode)
PEG-siRNA-PCL|siRNA-PEG-LHRH|MPEG-siRNA 甲氧基聚乙二醇修饰核酸
从实例学Kettle(一):获取股票行情数据