Python-PySide

我要开发桌面应用!

资源

正文

配置环境

在项目目录下:

shell
uv venv .venv
.venv\Scripts\activate
uv pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyside6
Resolved 4 packages in 3.68s
Prepared 4 packages in 2m 40s
░░░░░░░░░░░░░░░░░░░░ [0/4] Installing wheels...                                                                         warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
         If the cache and target directories are on different filesystems, hardlinking may not be supported.
         If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.
Installed 4 packages in 5.33s
 + pyside66.9.2
 + pyside6-addons6.9.2
 + pyside6-essentials6.9.2
 + shiboken66.9.2

快速开始

main.py 里放:

python
import sys
from PySide6.QtWidgets import QApplication, QLabel
 
app = QApplication(sys.argv)
label = QLabel("Hello, PySide6 + uv!")
label.show()
sys.exit(app.exec())

得到小小的也很可爱:

webp

PyInstaller 打包

执行命令:

shell
uv pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
.venv\Scripts\activate
pyinstaller --onefile --windowed main.py

注意

  • --onefile:打包成单个可执行文件(否则会生成一堆依赖文件夹)。

  • --windowed:GUI 模式,不会弹出终端黑框(Windows 上有效)。

得到 dist/main.exe,45333kb……

PyQt-Fluent-Widgets

下载其中的 PySide6 分支。

shell
uv venv .venv
.venv\Scripts\activate
uv pip install -r requirements.txt
uv pip install PySide6-Fluent-Widgets -i https://pypi.org/simple/

跑一下:

shell
cd examples/gallery
python demo.py

美得很:

webp