本文主要是介绍【PySide6学习笔记】一、PySide6、PySide2、PySide,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
python版本要求
- PySide6要求Python < 3.11, >=3.6
- PySide2要求Python>=2.7、!=3.0.*、!=3.1.*、!=3.2.*、!=3.3.*、!=3.4.*、< 3.11
- PySide 要求Python 2.6 或更高版本,不支持Python3
安装
使用pip install即可,如安装失败,请检查python版本。
PySide6
pip install PySide6
PySide2
pip install PySide2
PySide
pip install PySide
PySide6简单例子
import random
import sys
import os
import PySide6
from PySide6 import QtCore, QtWidgets# 将platforms加入临时环境变量
plugin_path = os.path.join(os.path.dirname(PySide6.__file__), 'plugins', 'platforms')
print(plugin_path)
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_pathclass MyWidget(QtWidgets.QWidget):def __init__(self):super().__init__()self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]self.button = QtWidgets.QPushButton("Click me!")self.text = QtWidgets.QLabel("Hello World", alignment=QtCore.Qt.AlignCenter)self.layout = QtWidgets.QVBoxLayout(self)self.layout.addWidget(self.text)self.layout.addWidget(self.button)self.button.clicked.connect(self.magic)@QtCore.Slot()def magic(self):self.text.setText(random.choice(self.hello))if __name__ == "__main__":app = QtWidgets.QApplication([])widget = MyWidget()widget.resize(800, 600)widget.show()sys.exit(app.exec())
代码改自Hello Qt for Python
效果图:
如有侵权,请联系删除。
这篇关于【PySide6学习笔记】一、PySide6、PySide2、PySide的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!