PySide

PySide是Qt公司开发的Python版GUI工具包。支持多WindowsLinuxmacOS平台。

简介

时间轴

2009年,发布PySide,支持Qt 4。


安装

使用pip安装

pip install pyside6

了解更多 >> PySide 文档:快速开始 PyPi:PySide6


快速入门

from PySide6 import QtCore, QtWidgets

app = QtWidgets.QApplication()
widget = QtWidgets
widget =  QtWidgets.QLabel('hello, world', alignment=QtCore.Qt.AlignCenter)
widget.resize(600, 400)
widget.show()
app.exec()

按钮点击时调用函数。

import sys
from PySide6 import QtCore, QtWidgets

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.button = QtWidgets.QPushButton("点击!")
        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.button_clicked)

    def button_clicked(self):
        self.text.setText("你点击了按钮。")


if __name__ == "__main__":
    app = QtWidgets.QApplication([])

    widget = MyWidget()
    widget.resize(800, 600)
    widget.show()

    sys.exit(app.exec())

了解更多 >> PySide 文档:快速开始


UI元素

PySide6.QtWidgets模块提供了一组UI元素,用于创建用户界面。


了解更多 >> PySide 文档:QtWidgets


布局

Designer

Qt Designer是一个设计构建用户图形界面的界面化工具。在终端使用命令即可启动:

pyside6-designer

了解更多 >> PySide 文档:将来自 Designer 或 QtCreator 的 .ui 文件与 QUiLoader 和 pyside6-uic 一起使用 PySide 文档:


打包分发

生成可执行文件

名称 描述
Nuitka 常用示例:nuitka --standalone --plugin-enable=pyside6 --include-data-dir=data=data --windows-disable-console main.py

其中:
--standalone
--include-data-dir=data=data 数据文件夹名称为data,可以放置数据或配置文件。
--windows-disable-console,不显示终端输出界面,开始打包可以先取消这个。
pyside6-deploy Pyside 6.4开始包含pyside6-deploy打包工具,是Nuitka的封装。
Pyinstaller

了解更多 >> PySide 文档:部署


资源

官网

教程

文章