欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 使用 Visual Studio Code (VS Code) 开发 Python 图形界面程序

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

2025/2/13 12:09:02 来源:https://blog.csdn.net/hqyhqyhq/article/details/145576438  浏览:    关键词:使用 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提供的帮助。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com