Pygame and PyGTK side by side

I am working on a python project where I have a pygame window, but I would also like to have a PyGTK window next to it with information about the objects inside the pygame window. However, when I run the PyGTK window, the pygame window freezes until PyGTK is closed, even if I make all the contents of PyGTK in the stream.

enter image description here Important snippets 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 
+6
source share
2 answers

I looked at the stack overflow question that OnGle said in his answer, and saw two solutions that I feel I can implement.


Solution 1

fooobar.com/questions/633221 / ... I could completely save part of the PyGTK program in a separate process and just send data between the two current programs. However, this seems a bit overboard for what I need.

Decision 2

I could use PGU or OcempGUI , which are Pygame libraries designed to simplify low-level graphical programming. Using one of them, I could forget about using PyGTK completely and just use ready-made objects from them.


Summary

While solution 1 supports my initial implementation of PyGTK, it may also be too complicated for such a simple program that I am doing. In addition, using solution 1 would also mean that I would have to continue to open two windows at once when my program starts up, which makes it seem cluttered and cumbersome.

Solution 2, on the other hand, purely integrates the list of objects in my Pygame project, and also reduces the amount of code I have to execute. I also don’t need to worry that different operating systems handle data transfer differently, as this is likely to be a problem with solution 1. In the end, this seems like the best solution to my situation.

+2
source

I do not know enough about gtk or threading in for python, to really help, but maybe you could use it as a job pyGame in Annex pyGTK

+3
source

All Articles