怎样搭建Qt for Python开发环境
1、按住win+R键,输入cmd打开命令行工具。在命令行中输入python -V 后回车,查看自己电脑中python版本是否符合安装要求。
2、在命令行中输入pip install PySide2 从pip包管理软件进行安装下芙囹买乐载。成功安装后,会有如图片所示 "稆糨孝汶;successfully installed PySide2-5.12.0" 出现。
3、在搜索栏输入IDLE,打开python 自带的 IDLE 工具。新建一个脚本文件并保存为helloworld.py.
4、在代码输入栏写上如下代码:import sysimport randomfrom PySide2 import QtCore, QtWidgets, QtGuic造婷用痃lass 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_())
5、点击 Run -> Run Module 对程序进行运行,会出现一个带有Helloword字样的界面。