开心网001首页,t124次列车,贵州民族大学教务管理系统
本文实例讲述了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, blue, (60, 60), (120, 60), 4) pygame.draw.line(windowsurface, blue, (120, 60), (60, 120)) pygame.draw.line(windowsurface, blue, (60, 120), (120, 120), 4) pygame.draw.circle(windowsurface, blue, (300, 50), 20, 0) pygame.draw.ellipse(windowsurface, red, (300, 250, 40, 80), 1) pygame.draw.rect(windowsurface, red, (textrect.left - 20, textrect.top - 20, textrect.width + 40, textrect.height + 40)) pixarray = pygame.pixelarray(windowsurface) pixarray[480][380] = black del pixarray windowsurface.blit(text, textrect) pygame.display.update() while true: for event in pygame.event.get(): if event.type == quit: pygame.quit() sys.exit()
运行后打出的图片如下:
希望本文所述对大家的python程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论