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()
时间: 2024-11-09 03:07:58