gpt4 book ai didi

python - 'QPixmap' 没有属性 'grabWindow'

转载 作者:太空宇宙 更新时间:2023-11-04 10:26:05 25 4
gpt4 key购买 nike

我正在尝试将我的代码从 PyQt4 转换为 PyQt5,但出现错误。

import sys
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication
from datetime import datetime

date = datetime.now()
filename = date.strftime('%Y-%m-%d_%H-%M-%S.jpg')
app = QApplication(sys.argv)
QPixmap.grabWindow(QApplication.desktop().winId()).save(filename, 'jpg')


Traceback (most recent call last):
File "C:\Python34\Projects\name.py", line 9, in <module>
QPixmap.grabWindow(QApplication.desktop().winId()).save(filename, 'jpg')
AttributeError: type object 'QPixmap' has no attribute 'grabWindow'

最佳答案

您应该改用QScreen::grabWindow()QPixmap::grabWindow() is deprecated in Qt 5.0 because :

there might be platform plugins in which window system identifiers (WId) are local to a screen.

关于python - 'QPixmap' 没有属性 'grabWindow',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29260686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com