<分区>
我正在开发一个 python 项目,其中有一个 pygame 窗口,但我还想同时在它旁边有一个 PyGTK 窗口,其中包含有关 pygame 窗口内对象的信息。但是,当我启动 PyGTK 窗口时,pygame 窗口会卡住,直到 PyGTK 窗口关闭,即使我在一个线程中执行所有 PyGTK 操作也是如此。
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