<<< Back to part 1

Getting Started - 02

Now that we've looked at a blank Pygame app, let's add CactusGUI to the mix.

To add CactusGUI to your project, you'll need to download the files and copy them into the same directory as your project. There are other ways to do it, but copying them into the project is by far the easiest and most effective. Once you've done that you can simply import the var 'gui'.

Here's a blank Pygame app with CactusGUI:

import pygame
from cactus_gui import gui

# Window Vars
windowWidth = 500
windowHeight = 300
windowTitle = 'CactusGUI Example'

# Init
screen = pygame.display.set_mode((windowWidth, windowHeight))
clock = pygame.time.Clock()
running = True

# Gui Startup
gui.setup( screen=screen, screen_width=windowWidth, screen_height=windowHeight )

#Add a white background for looks
gui.makeBackground('white bg')
gui['white bg'].style(owner='main', color=(255,255,255), z_order=-200)


while running:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			running = False 
		elif event.type == pygame.MOUSEMOTION:
		elif event.type == pygame.MOUSEBUTTONDOWN:
		elif event.type == pygame.MOUSEBUTTONUP:
		elif event.type == pygame.KEYDOWN:

When you run this it should give you a blank white window this time:

Notice that everything CactusGUI does is controlled through the var called 'gui'; this keeps the namespace from getting cluttered up.

Also notice the game loop at the bottom, unlike some other GUI's for pygame, CactusGUI does not take control of your game loop. Yes, this way you've got to write a bit more to attach it onto the loop, but this way the GUI does not prevent you from using any parts of Pygame.


Part 3 >>>