I'm using Python 2.7 and Ubuntu 14.04.
I find myself trying to this to insert my pygame window into my PyQt4 window.
On some platforms it is possible to embed the pygame display in an existing window. To do this, the environment variable SDL_WINDOWID must contain a string with the id of the destination window. This variable is checked when the pygame display is initialized.
This is my code:
from PyQt4 import QtGui, QtCore
import os
import subprocess
import sys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setWindowModality(QtCore.Qt.ApplicationModal)
MainWindow.setFixedSize(800, 600)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.iniMap()
def iniMap(self):
command = "xprop -root _NET_ACTIVE_WINDOW"
output = subprocess.Popen(["/bin/bash", "-c", command], stdout=subprocess.PIPE)
activeWindowID = str(output.communicate()[0].decode("utf-8").strip().split()[-1])
os.environ['SDL_WINDOWID'] = activeWindowID
import pygame
pygame.init()
screen = pygame.display.set_mode((565, 437), pygame.NOFRAME)
class frmMain(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(frmMain, self).__init__(parent, flags=QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
form = frmMain()
form.show()
sys.exit(app.exec_())
But this does not work, just show my PyQt window. I do not know if what I'm doing is wrong, or if directly pygame can not be integrated with PyQt.
What should I do to be able to embed my pygame in frmMain
?
Thank you very much.