import pygame, sys #导入pygame和sys模块
from pygame.locals import * #复制变量名到当前作用域
pygame.init() #调用函数
DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32) #创建一个宽400像素,高300像素的窗口
pygame.display.set_caption('Drawing') #设置窗口顶部显示的标题文本
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
BLUE = ( 0, 0, 255)
DISPLAYSURF.fill(WHITE)
pygame.draw.polygon(DISPLAYSURF, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(DISPLAYSURF, BLUE, (120, 60), (60,120))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 120), (120, 120), 4)
pygame.draw.circle(DISPLAYSURF, BLUE, (300, 50), 20, 0)
pygame.draw.ellipse(DISPLAYSURF, RED, (300, 250, 40, 80), 1)
pygame.draw.rect(DISPLAYSURF, RED, (200, 150, 100, 50))
pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[480][380] = BLACK
pixObj[482][382] = BLACK
pixObj[484][384] = BLACK
pixObj[486][386] = BLACK
pixObj[488][388] = BLACK
del pixObj
while True: #主循环
for event in pygame.event.get(): #遍历pygame.event.get()所返回的Event对象的列表
if event.type == QUIT: #检查event对象的type是否等于常量QUIT
pygame.quit() #停止pygame库
sys.exit() #终止程序
pygame.display.update() #把pygame.display.set_mode()所返回的Surface对象绘制到屏幕上