PythonProjects/QT/PyQt/1. 第一个QT程序.py
2024-03-01 14:06:22 +08:00

30 lines
1.2 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.

#!D:\Python311\python.exe
# -*- coding: utf-8 -*-
# @Time : 2024/2/26 13:02
# @Author : DC_DC
"""# 打印版本信息
from PyQt6.QtCore import PYQT_VERSION_STR, QT_VERSION_STR
print(QT_VERSION_STR)
print(PYQT_VERSION_STR)"""
import sys # 处理python解释器和系统的交互
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt6.QtGui import QIcon # 设置窗口的图标
def main():
app = QApplication(sys.argv) # 创建一个QApplication对象用于管理GUI应用程序的控制流和主事件循环
window = QMainWindow() # 创建一个QMainWindow对象这是程序的主窗口
window.setGeometry(500, 500, 300, 200) # 设置窗口的集合属性,即窗口在屏幕上的位置大小
window.setWindowTitle("DC_DC") # 设置窗口标题
window.setWindowIcon(QIcon('Photos/img.png')) # 设置窗口图标
QLabel("Hello, World!", window) # 创建一个QLabel对象并将其添加到主窗口中
window.show() # 显示主窗口
sys.exit(app.exec()) # 调用QApplication对象的exec()方法进入GUI应用程序的主事件循环sys.exit()则确保程序在退出事件循环侯正确地退出并返回一个退出码0
if __name__ == "__main__":
main()
pass