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_path
class 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
效果图:

如有侵权,请联系删除。
本文介绍了Python不同版本对PySide6、PySide2和PySide的兼容要求,并提供了安装步骤。通过实例展示了如何在PySide6中创建一个简单的Qt应用。
4万+

被折叠的 条评论
为什么被折叠?



