为什么PyQt5 QPixmap使python崩溃? [重复]

问题描述 投票:0回答:1
[当我尝试将此字符串列表转换为像素图时,它使python崩溃。对这个有任何建议吗?

openIcon = [ '16 13 5 1', '. c #040404', '# c #808304', 'a c None', 'b c #f3f704', 'c c #f3f7f3', 'aaaaaaaaa...aaaa', 'aaaaaaaa.aaa.a.a', 'aaaaaaaaaaaaa..a', 'a...aaaaaaaa...a', '.bcb.......aaaaa', '.cbcbcbcbc.aaaaa', '.bcbcbcbcb.aaaaa', '.cbcb...........', '.bcb.#########.a', '.cb.#########.aa', '.b.#########.aaa', '..#########.aaaa', '...........aaaaa' ] if __name__ == "__main__": from PyQt5.QtGui import QPixmap openIcon_p = QPixmap(openIcon) openIcon_p.save("openIcon.png")

使用:

Win32上的[Python 3.7.4(tags / v3.7.4:e09359112e,2019年7月8日,20:34:20)[MSC v.1916 64位(AMD64)]

PyQt5 == 5.13.0

python crash pyqt5 qpixmap
1个回答
1
投票
从控制台运行代码以查看错误消息。您需要在QApplication之前输入QPixmap

from PyQt5 import QtWidgets, QtGui import sys openIcon = [ '16 13 5 1', '. c #040404', '# c #808304', 'a c None', 'b c #f3f704', 'c c #f3f7f3', 'aaaaaaaaa...aaaa', 'aaaaaaaa.aaa.a.a', 'aaaaaaaaaaaaa..a', 'a...aaaaaaaa...a', '.bcb.......aaaaa', '.cbcbcbcbc.aaaaa', '.bcbcbcbcb.aaaaa', '.cbcb...........', '.bcb.#########.a', '.cb.#########.aa', '.b.#########.aaa', '..#########.aaaa', '...........aaaaa' ] if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) openIcon_p = QtGui.QPixmap(openIcon) openIcon_p.save("openIcon.png")

编辑:不添加行,代码给出以下错误消息:

QPixmap::fromImageInPlace: QPixmap cannot be created without a QGuiApplication QPixmap: Must construct a QGuiApplication before a QPixmap

有关说明,请参见Qt-Documentation。还提供了有关何时使用QtWidgets.QApplication以及何时使用[eyllanesc评论的QtGui.QGuiApplication]的说明
© www.soinside.com 2019 - 2024. All rights reserved.