手机
当前位置:查字典教程网 >脚本专栏 >python >python中pygame模块用法实例
python中pygame模块用法实例
摘要:本文实例讲述了python中pygame模块用法,分享给大家供大家参考。具体方法如下:importpygame,sysfrompygame....

本文实例讲述了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中pygame模块用法实例1

希望本文所述对大家的Python程序设计有所帮助。

【python中pygame模块用法实例】相关文章:

python解析模块(ConfigParser)使用方法

python实现ip查询示例

Python采集腾讯新闻实例

python解析xml模块封装代码

python解析中国天气网的天气数据

Python random模块(获取随机数)常用方法和使用例子

Python中使用PyHook监听鼠标和键盘事件实例

Python中的Numpy入门教程

Python中使用 Selenium 实现网页截图实例

python的urllib模块显示下载进度示例

精品推荐
分类导航