您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

python中pygame模块用法实例

2026/1/4 8:58:39发布22次查看
本文实例讲述了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程序设计有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product