Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding wxpython in pygame

I am looking for a way in which wxPython GUI elements can be added into pygame. If there is an alternative to solve the purpose of adding GUI elements to a pygame please suggest so. I am having problem in installing PGU.Thanks for help.

like image 305
hershey92 Avatar asked Jan 10 '12 02:01

hershey92


1 Answers

Nope; you CAN add wxWidgets to PyGame. It's trivial to add open/save dialogs, buttons, etc. Sometimes it gets nasty when you try to share areas, (as above, there's conflicting window systems), but it is definitely doable.

I wrote the following years ago, so it's messy; but at least it's simple. It should help you get started:

class SDLThread:
    def __init__(self,screen):
        self.m_bKeepGoing = self.m_bRunning = False
        self.screen = screen
        self.color = (255,0,0)
        self.rect = (10,10,100,100)
    def Start(self):
        self.m_bKeepGoing = self.m_bRunning = True
        thread.start_new_thread(self.Run, ())
    def Stop(self):
        self.m_bKeepGoing = False
    def IsRunning(self):
        return self.m_bRunning
    def Run(self):
        while self.m_bKeepGoing:
            pass
##            GetInput()
##            Draw()
        self.m_bRunning = False;
class SDLPanel(wx.Panel):
    def __init__(self,parent,ID,tplSize):
        global pygame
        wx.Panel.__init__(self, parent, ID, size=tplSize)
        self.Fit()
        os.environ['SDL_WINDOWID'] = str(self.GetHandle())
        os.environ['SDL_VIDEODRIVER'] = 'windib'
        import pygame
        pygame.init()
        icon = pygame.Surface((1,1));icon.set_alpha(0);pygame.display.set_icon(icon)
        global Surface
        Surface = pygame.display.set_mode(tplSize)
        self.thread = SDLThread(Surface)
        self.thread.Start()
    def __del__(self):
        self.thread.Stop()
like image 83
imallett Avatar answered Sep 29 '22 05:09

imallett