大赵传奇

GIS解决方案,webgis , 桌面、数据、服务--QQ276605216

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

显示一个窗口

# 这一行导入了 QApplication、QWidget 和 QLabel 类,它们是 PySide6 中用于创建应用程序和窗口组件的类。
from PySide6.QtWidgets import QApplication, QWidget,QLabel


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')

    # 创建了一个 QApplication 实例,用于管理整个应用程序的事件循环和资源分配。
    app = QApplication()

    # 创建一个空白的 QWidget 对象,它代表着我们的窗体。
    window = QWidget()
    window.setWindowTitle("Simple Window")
    window.setFixedSize(400, 300)

    # 创建一个 QLabel 对象,并将其作为子组件添加到窗体上。同时,设置标签的显示文本为 "Hello PySide6!"。
    label = QLabel("Hello PySide6!", window)
    label.move(10, 125)

    # 显示窗体
    window.show()

    # 启动应用程序的事件循环,等待事件的触发和处理,使窗体保持可响应状态。
    app.exec()
View Code

 

posted on 2025-05-15 13:36  赵长青  阅读(11)  评论(0)    收藏  举报