怎样搭建Qt for Python开发环境

2025-10-24 10:11:46

1、按住win+R键,输入cmd打开命令行工具。在命令行中输入python -V 后回车,查看自己电脑中python版本是否符合安装要求。

怎样搭建Qt for Python开发环境

2、在命令行中输入 pip install PySide2 从pip包管理软件进行安装下载。成功安装后,会有如图片所示 "successfully installed PySide2-5.12.0" 出现。

怎样搭建Qt for Python开发环境

怎样搭建Qt for Python开发环境

3、在搜索栏输入IDLE,打开python 自带的 IDLE 工具。新建一个脚本文件并保存为helloworld.py.

怎样搭建Qt for Python开发环境

4、在代码输入栏写上如下代码:

import sys

import random

from PySide2 import QtCore, QtWidgets, QtGui

class MyWidget(QtWidgets.QWidget):

    def __init__(self):

        super().__init__()

        self.text = QtWidgets.QLabel("Hello World")

        self.text.setAlignment(QtCore.Qt.AlignCenter)

        self.layout = QtWidgets.QVBoxLayout()

        self.layout.addWidget(self.text)

        self.setLayout(self.layout)

if __name__ == "__main__":

    app = QtWidgets.QApplication([])

    widget = MyWidget()

    widget.resize(400, 300)

    widget.show()

    sys.exit(app.exec_())

怎样搭建Qt for Python开发环境

5、点击 Run -> Run Module 对程序进行运行,会出现一个带有Helloword字样的界面。

怎样搭建Qt for Python开发环境

怎样搭建Qt for Python开发环境

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢