Here is a simple example of using the SGC toolkit. It is described in more detail below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import sgc from sgc.locals import * import pygame from pygame.locals import * pygame.display.init() pygame.font.init() screen = sgc.surface.Screen((640,480)) clock = pygame.time.Clock() btn = sgc.Button(label="Clicky", pos=(100, 100)) btn.add(0) while True: time = clock.tick(30) for event in pygame.event.get(): sgc.event(event) if event.type == QUIT: exit() screen.fill((0,0,0)) sgc.update(time) pygame.display.flip()
The file is available as example/helloworld.py in the source distribution.
import sgc from sgc.locals import *
Here we import everything we need from sgc.
import pygame from pygame.locals import * pygame.display.init() pygame.font.init()
The toolkit needs to have the display and font modules initialised; pygame.init() would suffice.
screen = sgc.surface.Screen((640,480))
This creates a screen object, in much the same way as pygame.display.set_mode() does. This is required for the toolkit to function.
btn = sgc.Button(label="Clicky", pos=(100, 100)) btn.add(0)
This creates a new button widget, setting the label to ‘Clicky’ and the top-left position of the widget to (100,100). The other line adds the button to the screen, with the 0 specifying the focus order of the widget, meaning the button will be the first widget to be focused when the user hits the TAB key.
This function sends an event through to the toolkit. This function should appear in your event loop in order to handle all incoming events.
This function should be called on each frame before the screen is updated. It should be given the time passed since the last frame; this is usually obtained from clock.tick().