当前位置:网站首页>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

边栏推荐
- 【无标题】
- What are the software development modes (software engineering development mode)
- Samba server configuration (when a server is required)
- MySQL - Design game user information table
- 荧光量子点修饰siRNA-QDs|纳米金修饰siRNA-Au(RNA修饰方式方法)
- mos管闩锁效应理解学习
- 1. Promise usage in JS, 2. The concept and usage of closures, 3. The difference between the four methods and areas of object creation, 4. How to declare a class
- In the past six months, I have done those things about the automatic return of the transaction link...
- 怎么实现您的个人知识库?
- 错误解决:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255]
猜你喜欢

MySQL Data Query - Union Query

336. 回文对

荧光量子点修饰siRNA-QDs|纳米金修饰siRNA-Au(RNA修饰方式方法)

一 JS中Promise用法、二闭包的概念与用法、三对象创建的四种方式与区区别、四 如何声明一个类

Cooler Navigation helps you shop easily in shopping malls without confusion

Writing Elegant Kotlin Code: Talk About What I Think "Kotlinic"

940. 不同的子序列 II

.NET 6.0中使用Identity框架实现JWT身份认证与授权
![[ACTF2020 Freshman Competition]Exec 1](/img/1e/a3c19d514207e6965d09c66b86e519.png)
[ACTF2020 Freshman Competition]Exec 1

Analysis of Crypto in Pi 2
随机推荐
Where is Naive Bayes "naive"?
Hyaluronic acid-siRNA透明质酸修饰核糖核酸|peptide–siRNA 多肽偶连RNA/DNA核酸(齐岳PNA修饰物)
ALBERT:A Lite BERT for Self-supervised Learning of Language Representations
单壁碳纳米管-DNA复合物(SWCNT-DNA)|作用机理
ALBERT: A Lite BERT for Self-supervised Learning of Language Representations
ES6用法,面试大全
4. Implementation Guide for GET_ENTITYSET Method of SAP ABAP OData Service Data Provider Class
The cornerstone of distributed: reliability - What a tangled web we weave
一 JS中Promise用法、二闭包的概念与用法、三对象创建的四种方式与区区别、四 如何声明一个类
Kotlin - Coroutine Scope CoroutineScope, Coroutine Builder CoroutineBuilder, Coroutine Scope Function CoroutineScope Functiom
Common power symbols meaning sharing
叶酸&适配体修饰DNA纳米载体|CdS纳米颗粒修饰DNA|科研试剂
Cooler Navigation helps you shop easily in shopping malls without confusion
The younger brother asked: Is the work of a programmer a day’s work of code?
VR直播营销需求增加,数据模块为我们铺路
Permutations of a small feat: cantor
JS实现百叶窗特效
根据昵称首字母生成头像
怎么实现您的个人知识库?
940. 不同的子序列 II