本文实例讲述了python中pygame模块用法,分享给大家供大家参考。具体方法如下:
import pygame, sys
from pygame.locals import *
#set up pygame
pygame.init()
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption("hello, world")
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
basicFont = pygame.font.SysFont(None, 48)
text = basicFont.render("Hello ,world", True, WHITE, BLUE)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery
windowSurface.fill(WHITE)
pygame.draw.polygon(windowSurface, GREEN, ((146, 0),
(291, 106), (236, 277), (56, 277), (0, 106)))
pygame.draw.line(windowSurface, B