Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

qt

PySide2/PySide6、PyQT5/PyQT6
基于QT的python库,优点:控件比较丰富跨平台体验好,文档完善用户多

安装小指南

安装PySide2:

1、从Pypi下载安装

pip install PySide2
如果安装太慢,可以尝试:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyside2
这样就会从清华镜像源安装pyside库

2、通过http下载安装

pip install –index-url=http://download.qt.io/snapshots/ci/pyside/5.13.0/latest pyside2 –trusted-host download.qt.io
5.13.0是版本号,根据自己的需要选择相应的版本

3、踩坑

开开心心找了一个案例:

from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton, QPlainTextEdit

app = QApplication([])

window = QMainWindow()
window.resize(500, 400)
window.move(300, 310)
window.setWindowTitle(‘薪资统计’)

textEdit = QPlainTextEdit(window)
textEdit.setPlaceholderText(“请输入薪资表”)
textEdit.move(10,25)
textEdit.resize(300,350)

button = QPushButton(‘统计’, window)
button.move(380,80)

window.show()

app.exec_()
一运行就报错:

qt.qpa.plugin: Could not load the Qt platform plugin “windows” in “” even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: direct2d, minimal, offscreen, windows.
PySide2是QT官方出的Python的QT封装,不过默认安装运行的时候会出现一些小问题,可能是系统里已经安装了其他版本的QT的原因,

可以通过添加环境变量来解决:

import os
envpath = r’D:\anaconda3\Lib\site-packages\PySide2\plugins\platforms’
os.environ[“QT_QPA_PLATFORM_PLUGIN_PATH”] = envpath
这样就能正常运行了!

评论