Tuesday, October 4, 2011

Pygame - Minimal Code For Screen Exercise

The minimal code required to set the screen up in pygame.  I've been trying to get my son to do this from memory.  This is a short repetitive exercise.  I like it because it uses a while loop and a for loop in addition to two ways of importing libraries.  It also gives a satisfying black window when it is run.  My student created five programs using this exact code, with the use of a printout of the code.  He ran each code to test it.  I was surprised that he seemed to enjoy the drill.  He ended up turning the printout over to try and do as much from memory as possible.    I intend to keep up with this drill and even created another drill with rectangles.





   1    import pygame, sys
   2    from pygame.locals import *
   3    
   4    pygame.init()
   5    pygame.display.set_mode((800, 600), 0, 32)
   6    
   7    while True:
   8        for event in pygame.event.get():
   9            if event.type == QUIT:
  10                pygame.quit()
  11                sys.exit()
  12        pygame.display.update()




No comments:

Post a Comment