Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame and PyGTK side by side [duplicate]

I'm working on a python project where I have a pygame window, but I'd also like to have a PyGTK window next to it at the same time with information about objects inside the pygame window. However, when I start the PyGTK window the pygame window freezes until the PyGTK one is closed, even if I do all the PyGTK stuff in a thread.

enter image description here Important pieces of code from my project:

import thread
import pygtk
import gtk

class SelectList:
    def __init__(self, parent):
        self.parent = parent
        self.initWindow()
        self.main()

    def main(self):
        gtk.main()

    def initWindow(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.window.connect("destroy", self.destroy)

        self.window.set_title("Selection info")
        self.window.set_position(gtk.WIN_POS_CENTER)

        # junk that I didn't bother including in this example
        # ...

        self.window.show_all()

    #This is only connected to the main window
    #When this is called it iterates through every toplevel window and closes it
    def destroy(self, widget, data=None):
        for i in gtk.window_list_toplevels():
            i.destroy()
        gtk.main_quit()


def openList(instance):
    SelectList(instance)

class Maker:
    def __init__(self):
        # more stuff that I won't include
        pass

    def logic(self, newkeys):
        if K_l in newkeys:
            thread.start_new_thread(openList, (self, ))

    def main(self):
        while True:
            # pygame stuff, including sending all new key presses to logic method
            pass
like image 257
Spooky Avatar asked Dec 12 '15 05:12

Spooky


1 Answers

I don't know enough about gtk or threading in python to really help but perhaps you could use this as a work around pyGame within a pyGTK application

like image 127
OnGle Avatar answered Sep 22 '22 14:09

OnGle