Adding wxpython to pygame

I am looking for a way in which wxPython GUI elements can be added to pygame. If there is an alternative to the task of adding GUI elements to pygame, suggest this. I had a problem installing PGU. Thanks for the help.

+5
source share
2 answers

Nope; you can add wxWidgets to PyGame. It is trivial to add open / saved dialogs, buttons, etc. Sometimes it’s unpleasant when you try to exchange areas (as above, there are conflicting window systems), but it is definitely doable.

I wrote a few years ago, so it's messy; but at least it's simple. This 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()
+3
source

, , wxPython ( wxWidgets ++) , ( ).

Pygame SDL , SDL , .

:

  • ctypes, C- , - pygame.

( , ):

  • , , ( ).

, :

  • pygame, /, .

  • wx, , DC ( ), pygame, , , ( ) pygame context wx . wx, .

, .

0

All Articles