Hardware Reference
In-Depth Information
Esc key. A close event is either the user clicking the close cross on the window or the operating
system telling the program to quit because it is going to shut down. If your program sees any
of those events, it calls a terminate function that prints out a message. hen it quits
pygame to release any memory it grabbed, and it exits to the operating system.
Getting the Code to Do More
Well, that was not very exciting, was it? Let's get the code to do a little more. Take a look at
Listing 11-2.
Listing 11-2 Windows2 Test Program
#!/usr/bin/env python
“””
Window2 to open up a window on the desktop, draw something in it
and read the mouse position upon a click
“””
import piface.pfio as pfio # piface library
import os, pygame, sys
pygame.init() # initialise graphics interface
pfio.init() # initialise pfio
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption(“LED controll”)
screen = pygame.display.set_mode([190,160],0,32)
box = False
def main():
drawBox(box)
while True :
checkForEvent()
def drawBox(state):
boxNum = 0
# first draw the box
# - fill colour depends on sequence bit state
if state :
pygame.draw.rect(screen,(255,0,0), ;
(50, 70, 40,40), 0)
else :
pygame.draw.rect(screen,(180,180,180),
(50, 70, 40,40), 0)
Search WWH ::




Custom Search