当前位置: 首页 > article >正文

使用 Visual Studio Code (VS Code) 开发 Python 图形界面程序

安装Python、VS Code

Documentation for Visual Studio Code

Python Releases for Windows | Python.org

更新pip

>python.exe -m pip install --upgrade pip
Requirement already satisfied: pip in c:\users\xxx\appdata\local\programs\python\python312\lib\site-packages (23.2.1)
Collecting pip
  Obtaining dependency information for pip from https://files.pythonhosted.org/packages/c9/bc/b7db44f5f39f9d0494071bddae6880eb645970366d0a200022a1a93d57f5/pip-25.0.1-py3-none-any.whl.metadata
  Downloading pip-25.0.1-py3-none-any.whl.metadata (3.7 kB)
Downloading pip-25.0.1-py3-none-any.whl (1.8 MB)
   ---------------------------------------- 1.8/1.8 MB 776.0 kB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.2.1
    Uninstalling pip-23.2.1:
      Successfully uninstalled pip-23.2.1
Successfully installed pip-25.0.1

安装PyQt5

>pip install PyQt5
Collecting PyQt5
  Downloading PyQt5-5.15.11-cp38-abi3-win_amd64.whl.metadata (2.1 kB)
Collecting PyQt5-sip<13,>=12.15 (from PyQt5)
  Downloading PyQt5_sip-12.17.0-cp312-cp312-win_amd64.whl.metadata (492 bytes)
Collecting PyQt5-Qt5<5.16.0,>=5.15.2 (from PyQt5)
  Downloading PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl.metadata (552 bytes)
Downloading PyQt5-5.15.11-cp38-abi3-win_amd64.whl (6.9 MB)
   ---------------------------------------- 6.9/6.9 MB 884.3 kB/s eta 0:00:00
Downloading PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
   ---------------------------------------- 50.1/50.1 MB 1.1 MB/s eta 0:00:00
Downloading PyQt5_sip-12.17.0-cp312-cp312-win_amd64.whl (58 kB)
Installing collected packages: PyQt5-Qt5, PyQt5-sip, PyQt5
Successfully installed PyQt5-5.15.11 PyQt5-Qt5-5.15.2 PyQt5-sip-12.17.0

编码

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QMessageBox # type: ignore

# 创建主窗口
class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("PyQt 示例")

        # 添加标签
        label = QLabel("你好,PyQt!", self)

        # 添加按钮
        button = QPushButton("点击我", self)
        button.clicked.connect(self.on_button_click)

        # 设置布局
        layout = QVBoxLayout()
        layout.addWidget(label)
        layout.addWidget(button)
        self.setLayout(layout)

    def on_button_click(self):
        QMessageBox.information(self, "提示", "你点击了按钮!")

# 运行应用程序
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyApp()
    window.show()
    sys.exit(app.exec_())

运行程序

程序示例

特此感谢DeepSeek提供的帮助。


http://www.kler.cn/a/542040.html

相关文章:

  • 【Windows】PowerShell 缓存区大小调节
  • 解锁Netty:Channel更替与HashMap管理的奇妙联动
  • 图像锐化(QT)
  • 【网络安全】服务器安装Docker及拉取镜像教程
  • AF3 drmsd函数解读
  • 『Apisix进阶篇』结合Consul作服务发现实战演练
  • Day59_20250207_图论part4_110.字符串接龙|105.有向图的完全可达性|106.岛屿的周长
  • Spring Boot整合DeepSeek实现AI对话(API调用和本地部署)
  • 淘宝App交易链路终端混合场景体验探索
  • 教育局网络设备运维和资产管理方案
  • SpringBoot中能被外部注入以来的注解
  • 网站快速收录攻略:提升页面加载速度
  • django中间件,中间件给下面传值
  • 05:定时器生成频率不同的波形
  • Rocketmq 和 Rabbitmq ,在多消费者的情况下,可以实现顺序消费吗
  • 使用腾讯云大模型知识引擎搭建满血deepseek
  • arcgis for js实现层叠立体效果
  • C++ 用Eigen的非线性求解LevenbergMarquardt,亲测ok
  • Python 透明数字时钟
  • 独立站赋能反向海淘:跨境代购系统的用户体验与支付解决方案
  • 2025.2.10 每日学习记录3:技术报告只差相关工作+补实验
  • 在npm上传属于自己的包
  • 【RabbitMQ的x-death头】消息死亡记录头流转示例
  • 攻防世界32 very_easy_sql【SSRF/SQL时间盲注】
  • android的第一个app项目(java版)
  • C++ Primer 简单语句