三、PyQt窗口处理
1. 第一个PyQt窗口
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | from PyQt5.QtWidgets import QApplication,QWidget
import sys
# 1.创建应用程序
app = QApplication(sys.argv)
# 2.创建窗口
w = QWidget()
# 3.显示窗口
w.show()
# 4.等待窗口停止
sys.exit(app.exec())
|
执行代码,就会显示PyQt窗口:

2. PyQt模块简介
PyQt中有非常多的功能模块,开发中最常用的功能模块主要有三个:
主要和时间、文件与文件夹、各种数据、流、URLs、mime类文件、进程与线程一起使用
PyQt的其它模块

3. 设置窗口的标题和图标
应用程序图标是一个小的图像,通常在标题栏的左上角显示。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon
import sys
# 1.创建应用程序
app = QApplication(sys.argv)
# 2.创建窗口
w = QWidget()
# 设置窗口标题
w.setWindowTitle('黑马窗口')
icon = QIcon('qq.png')
# 设置图标
w.setWindowIcon(icon)
# 3.显示窗口
w.show()
# 4.等待窗口停止
sys.exit(app.exec())
|
运行程序:

4. 显示提示
在设计界面时应改尽可能人性化,对于关键的操作,给出相关信息的提示会非常有用,就可以使用气泡提示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon
import sys
# 1.创建应用程序
app = QApplication(sys.argv)
# 2.创建窗口
w = QWidget()
# 修改窗口标题
w.setWindowTitle('气泡提示窗口')
"""------------------ 气泡提示 ------------------"""
w.setToolTip('这个一个气泡提示的窗口')
# 3.显示窗口
w.show()
# 4.等待窗口停止
sys.exit(app.exec())
|
运行程序:
