显示一个窗口

# 这一行导入了 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()