pyside6_study/chapter1/快速入门.py
2025-04-25 21:07:10 +08:00

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 导入 sys 模块,用于处理命令行参数
import sys
# 从 PySide6.QtWidgets 模块中导入 QApplication、QWidget 和 QLabel 类
from PySide6.QtWidgets import QApplication, QWidget, QLabel
# 创建 QApplication 对象,管理应用程序的控制流和主要设置
# sys.argv 是命令行参数的列表,确保应用程序可以接收命令行输入
app = QApplication(sys.argv)
# 创建一个 QWidget 对象,作为应用程序的主窗口
window = QWidget()
# 设置窗口的标题为 "Hello World"
window.setWindowTitle("Hello World")
# 设置窗口的固定大小为 200x200 像素
window.setFixedSize(200, 200)
# 创建一个 QLabel 对象,显示文本 "Hello World!"
# 第二个参数指定 QLabel 的父对象为 window即标签会显示在窗口内
label = QLabel('Hello World!', window)
# 显示窗口
window.show()
# 进入应用程序的主事件循环,等待用户交互
# app.exec() 会阻塞程序,直到窗口关闭
m = app.exec() # 执行app的exec()方法,进入事件循环,若关闭窗口,则返回整数值
sys.exit(m) # 通知python解释器结束程序运行