python使用PyGame绘制图像并保存为图片文件的方法

yipeiwu_com6年前Python基础

本文实例讲述了python使用PyGame绘制图像并保存为图片文件的方法。分享给大家供大家参考。具体实现方法如下:

''' pg_draw_circle_save101.py
draw a blue solid circle on a white background
save the drawing to an image file
for result see /zb_users/upload/202003/i4eeohfkxw4 .tga .png or .jpg
fname = "circle_blue.png"
pg.image.save(win, fname)
print("file {} has been saved".format(fname))
# update the display window to show the drawing
pg.display.flip()
# event loop and exit conditions
# (press escape key or click window title bar x to exit)
while True:
  for event in pg.event.get():
    if event.type == pg.QUIT:
      # most reliable exit on x click
      pg.quit()
      raise SystemExit
    elif event.type == pg.KEYDOWN:
      # optional exit with escape key
      if event.key == pg.K_ESCAPE:
        pg.quit()
        raise SystemExit

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

相关文章

Python数据类型之Tuple元组实例详解

本文实例讲述了Python数据类型之Tuple元组。分享给大家供大家参考,具体如下: tuple元组 1.概述 本质上是一种有序的集合,和列表非常的相似,列表使用[]表示,元组使用()表...

Python中numpy模块常见用法demo实例小结

本文实例总结了Python中numpy模块常见用法。分享给大家供大家参考,具体如下: import numpy as np arr = np.array([[1,2,3],...

Python实现判断给定列表是否有重复元素的方法

Python实现判断给定列表是否有重复元素的方法

本文实例讲述了Python实现判断给定列表是否有重复元素的方法。分享给大家供大家参考,具体如下: 题目很简单,只是简单温习一个方法,most_common,这是collection模块中...

利用rest framework搭建Django API过程解析

利用rest framework搭建Django API过程解析

思路步骤: 创建一个可以序列化的类 去数据库取数据交给序列化的类处理 把序列化的数据返回前端 操作流程: # 安装模块 pip install djangorestfra...

Python中单例模式总结

一、单例模式     a、单例模式分为四种:文件,类,基于__new__方法实现单例模式,基于metaclass方式实现    ...