Python Pygame嵌入PyQt时不返回事件

Python Pygame嵌入PyQt时不返回事件,python,pyqt,pygame,pygame-surface,Python,Pyqt,Pygame,Pygame Surface,我正在测试一个应用程序,UI使用PyQt4,其中嵌入了Pygame。可以说,它使用一个计时器来“更新”自身,并且在timerEvent函数中,Pygame尝试检索所有检测到的事件。问题是,Pygame没有检测到任何事件 这是我的代码的一个极简版本 #!/etc/python2.7 from PyQt4 import QtGui from PyQt4 import QtCore import pygame import sys class ImageWidget(QtGui.QWidget):

我正在测试一个应用程序,UI使用PyQt4,其中嵌入了Pygame。可以说,它使用一个计时器来“更新”自身,并且在timerEvent函数中,Pygame尝试检索所有检测到的事件。问题是,Pygame没有检测到任何事件

这是我的代码的一个极简版本

#!/etc/python2.7
from PyQt4 import QtGui
from PyQt4 import QtCore
import pygame
import sys

class ImageWidget(QtGui.QWidget):
    def __init__(self,surface,parent=None):
        super(ImageWidget,self).__init__(parent)
        w=surface.get_width()
        h=surface.get_height()
        self.data=surface.get_buffer().raw
        self.image=QtGui.QImage(self.data,w,h,QtGui.QImage.Format_RGB32)

        self.surface = surface

        self.timer = QtCore.QBasicTimer()
        self.timer.start(500, self)

    def timerEvent(self, event):
        w=self.surface.get_width()
        h=self.surface.get_height()
        self.data=self.surface.get_buffer().raw
        self.image=QtGui.QImage(self.data,w,h,QtGui.QImage.Format_RGB32)
        self.update()

        for ev in pygame.event.get():
            if ev.type == pygame.MOUSEBUTTONDOWN:
                print "Mouse down"

    def paintEvent(self,event):
        qp=QtGui.QPainter()
        qp.begin(self)
        qp.drawImage(0,0,self.image)
        qp.end()


class MainWindow(QtGui.QMainWindow):
    def __init__(self,surface,parent=None):
        super(MainWindow,self).__init__(parent)
        self.setCentralWidget(ImageWidget(surface))



pygame.init()
s=pygame.Surface((640,480))
s.fill((64,128,192,224))
pygame.draw.circle(s,(255,255,255,255),(100,100),50)

app=QtGui.QApplication(sys.argv)
w=MainWindow(s)
w.show()
app.exec_()
当Pygame窗口嵌入PyQt应用程序时,如何获取Pygame事件?

您不能


TL;博士
您不能也不应该组合两个具有自己的事件循环的库,例如,现在Qt eventloop正在阻止pygame事件循环。

您不能也不应该组合两个具有自己的eventloop的库,例如,现在Qt eventloop正在阻止pygame eventloop。因此,在这种情况下不可能获取pygame事件?是的,不可能。现在我很抱歉,如果Qt涵盖pygame的所有功能,我不理解使用pygame的必要性