python - Pygame 和 PyGTK 并排

标签 python pygame pygtk

<分区>

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

enter image description here 我项目中的重要代码片段:

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

最佳答案

我对 gtk 或 python 中的线程了解不够,无法提供真正的帮助,但也许您可以使用它来解决 pyGame within a pyGTK application

关于python - Pygame 和 PyGTK 并排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34236469/

相关文章:

python - OSX 上的 Tensorflow 0.10 (CUDA) 在 python 导入时出现段错误

python - 使用Python ffmpeg将音频文件和所有帧图片加入视频格式

python - 处理 pygtk/glade 中的删除事件

python - 如何让我的 Sprite 在 pygame 中不横向移动?

python - pygame 错误 : DLL load failed (Win32)

python - 在 GTK 主循环中向用户请求信息

python - Ubuntu 中的 PyGTK 图标模糊

python - 使用 Python 查找电子邮件正文中的链接

python - 为什么 Python 3.4 给出了大数除法的错误答案,我该如何测试整除性?

python - 模块无法加载,仅标题发生变化(pygame)