python - PyQt5:截图给出错误(xcb)
问题描述
我是 python 新手,所以这可能很容易,如果是的话,我很抱歉,但我找不到这样做的方法。问题是当我调用 snip() 时,无论在哪里,它都会截取一次屏幕截图,但是当我再次按下按钮时,它会停止、冻结然后强制退出。到目前为止,我遇到了 2 个不同的错误。一个是以下,每当我第二次单击该按钮时:
Gdk 消息:python3:X 服务器上的致命 IO 错误 11(资源暂时不可用):0。被杀
我在更大的项目中找到的另一个是以下一个:
[xcb] 处理队列时序列号未知
[xcb] 这很可能是一个多线程客户端并且 XInitThreads 没有被调用
[xcb] 中止,抱歉。
python3:../../src/xcb_io.c:259:poll_for_event:断言'!xcb_xlib_threads_sequence_lost'失败。
中止
有没有办法在我每次单击按钮时截取屏幕而不出现此问题?这是问题的简化代码。感谢你们提供的任何帮助。
import pyscreenshot as ImageGrab
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow,self).__init__()
self.initUI()
def button_clicked(self):
self.label.setText("you pressed the button")
self.snip() #heres the problem
self.update()
def initUI(self):
self.setGeometry(200, 200, 300, 300)
self.setWindowTitle("Tech With Tim")
self.label = QtWidgets.QLabel(self)
self.label.setText("my first label!")
self.label.move(50,50)
self.b1 = QtWidgets.QPushButton(self)
self.b1.setText("click me!")
self.b1.clicked.connect(self.button_clicked)
def update(self):
self.label.adjustSize()
def snip(self):
img = ImageGrab.grab(bbox=(200, 300, 400, 500))
img.show()
def window():
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())
window()
解决方案
推荐阅读
- excel - 使用 VBA 宏创建用于过滤列的选择菜单
- python - “API”对象没有使用 Tweepy 的“搜索”属性
- sql - 防止在查询运行和完成之间显示新数据
- reactjs - 如何在将状态传递给子组件之前正确修改父组件的状态
- protocol-buffers - 在 protobuf3 中使用 optional 来检查可空性是一个好习惯吗?
- python - 如何从 np.where 条件中删除异常值
- c++ - 在不使用向量的情况下在 C++ 中的数组末尾插入元素
- php - Woocommerce 审查订单总挂钩两次回显结果
- sql - 将字符串转换为浮点数/小数 - 大查询
- .net-5 - dotnet publish,带有框架引用的核心项目,发布配置失败