view 000/005.py @ 12:9dc97f88e274 default tip

Added CC0 license
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 08 Jul 2012 19:56:38 +0200
parents 03fe34478f69
children
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygame
import pygame.locals as pg


def initialize_screen():
    """Initialize pygame, create a window and fill it with gray.
    Return the screen surface.
    """
    pygame.display.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((0x66, 0x66, 0x66))
    return screen

def load_and_display_image(screen):
    """Load the image and display it in the middle of the screen."""
    image = pygame.image.load('cup.png')
    image = image.convert()
    image.set_colorkey((0xff, 0x00, 0xff))
    screen_rect = screen.get_rect()
    image_rect = image.get_rect()
    image_rect.center = screen_rect.center
    screen.blit(image, image_rect)

def wait_for_quit():
    """Sit there doing nothing until the window is closed."""
    pygame.display.update()
    while True:
        event = pygame.event.wait()
        if event.type == pg.QUIT:
            return


if __name__ == '__main__':
    screen = initialize_screen()
    load_and_display_image(screen)
    wait_for_quit()