[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Gui



> There are some GUIs that are implemented in Python/Pygame.
>
> The simplest is Mike Leonhard's GUI, at http://tamale.net/chat/ . The
> GUI is in the files 'widgets.py' and 'widgetdemo.py'.
>
> Ocemp GUI is new, more extensive (and complex), and maintained by
> Marcus von Appen, who I believe follows this list (pygame-users).
>
> PyUI2 is a recent resuscitation of PyUI, and includes Pygame
> renderers, for use within Pygame.


I recommend Mike Leonhard's GUI, and what his Web page says about the
"Model/View/Controller" design for programs. And his "evil Bert" picture.

I had some trouble with PyUI, finding several bugs in the version I
downloaded, but haven't tried PyUI2 yet.

For Leonhard's GUI, you can extend it by adding the following Image class
(by me based on his other code; use it freely for anything):

class ImageClass:
    """A static image."""
    def eventproc( self, event ):
        pass
    def __init__( self, manager, rect, image, foreground=WHITE,
background=None ):
        self.manager = manager
        self.rect = Rect(rect)
        self.image = pygame.image.load(image).convert()
        self.foreground = foreground
        self.background = background
    def draw( self, screen ):
        screen.set_clip( screen.get_clip().clip( self.rect ) )
        # background is set
        if self.background != None:
            # fill background
            screen.fill( self.background, self.rect )
        screen.blit(self.image, self.rect)


Also in the function settext( self, newtext ), the following line should
be aded to the beginning:

self.lines = [] ## Clear previous text

Kris