Integrating pgu to pyherc

I have been writing a simple rogue-like game with tiles support. I’m using Python + pygame and have found that user interface stuff is actually quite hard for me to get correctly. After looking around a bit, I found a nice looking library called pgu ( and decided to give it a try.

Integrating existing codebase and pgu was simple enough and soon I had a rudimentary start menu up and running. Rest of the program still used routines I had written earlier. All was well, other than start menu not clearing the screen after game ended. Buttons were drawn on top of the what ever happened to be left on the screen after the game ended.

Solution for this was really simple. pgu.gui.basic.Image is a Widget that can display a pygame Surface or load image from disk and display it. It is also unfocusable, so adding it to the StarMenu was simple:

bg = pgu.gui.Image(self.surface_manager.getImage(images.image_start_menu))
self.add(bg, 0, 0)

b = pgu.gui.Button("New game", width=150)
self.add(b, 325, 200)
b.connect(pgu.gui.CLICK, self.__startNewGame)

b = pgu.gui.Button("Load game", width=150)
self.add(b, 325, 250)

b = pgu.gui.Button("Quit", width=150)
self.add(b, 325, 300)
b.connect(pgu.gui.CLICK, self.__quit_game)

After that, I had a nice little start menu, with three buttons on it. New game calls __startNewGame – method for starting a new game and quit button closes the program.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s