在 Windows 和 Linux 的主窗口中运行线程 [英] Run thread in main window for both Windows and Linux

查看:57
本文介绍了在 Windows 和 Linux 的主窗口中运行线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个在 GUI(文本区域、按钮、菜单等)内运行的游戏 我已经用 wxpython 创建了一个 GUI.我在主窗口中创建了一个面板,它运行一个 pygame 线程.

I am creating a game to run inside a GUI (text area, button, menu etc) I've created a GUI with wxpython. I create a panel inside the main window, which runs a pygame thread.

在 Windows 上,pygame 线程完美在主窗口内运行.但是在 Linux 上,pygame 会在一个新窗口中弹出.我如何设置它以便 Windows 和 Linux 在主窗口中运行线程?

On Windows, the pygame thread runs perfectly inside the main window. But on Linux, the pygame pop up on a new window. How can I set this such that both windows and Linux run the thread in the main window?

class SDLPanel(wx.Panel):
    def __init__(self,parent,ID,tplSize):
        global pygame
        global pygame_init_flag
        wx.Panel.__init__(self, parent, ID, size=tplSize)
        self.Fit()

        if (sys.platform == 'win32'):
            os.environ['SDL_WINDOWID'] = str(self.GetHandle())
            os.environ['SDL_VIDEODRIVER'] = 'windib'
        else:
            os.environ['SDL_VIDEODRIVER'] = 'x11'

        #here is where things change if pygame has already been initialized
        #we need to do so again
        if pygame_init_flag:
            #call pygame.init() on subsaquent windows
            pygame.init()
        else:
            #import if this is the first time
            import pygame
        pygame_init_flag = True #make sure we know that pygame has been imported
        pygame.display.init()
        window = pygame.display.set_mode(tplSize)
        self.thread = SDLThread(window)
        self.thread.Start()

    def __del__(self):
        self.thread.Stop()
        print "thread stoped"
        #very important line, this makes sure that pygame exits before we
        #reinitialize it other wise we get errors
        pygame.quit() 

推荐答案

已解决问题.

在主窗口中我们必须 self.Show()Idk 为什么在 linux 中必须显示主窗口.相同的代码.Tks 全部

In main window we must self.Show() Idk why in linux the main window must be showed . Same code. Tks all

这篇关于在 Windows 和 Linux 的主窗口中运行线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆