首页 > 代码库 > pygame 初记

pygame 初记


import traceback
import pygame
from pygame.locals import *

pygame.display.init()

sizes = {
    "screen" : [ 640, 480 ]
}

colors = {
    "screen" : ( 255, 255, 255 )
}

screen = pygame.display.set_mode( sizes["screen"], 0, 32 )


def cin():
    for e in pygame.event.get():
        if e.type == KEYDOWN:
            if e.key == K_ESCAPE:
                return False
    return True


def draw():
    screen.fill( colors["screen"] )
    pygame.display.update()


def prepare( func ):
    def _pre():
        pygame.event.set_grab( True )
        func()
        pygame.event.set_grab( False )
        pygame.quit()
    return _pre


@prepare
def main():
    while True:
        if not cin():
            break
        draw()
        

if __name__ == '__main__':
    try:
        main()
    except:
        traceback.print_exc()
        pygame.quit()
        input()


pygame 初记