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

yipeiwu_com5年前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加载带有注释的Json文件实例

由于json文件不支持注释,所以如果在json文件中标记了注释,则使用python中的json.dump()无法加载该json文件。 本文旨在解决当定义“//”为json注释时,如何正确...

在python中只选取列表中某一纵列的方法

如下所示: >>> a=random.randint(1,6,(5,3)) >>> a array([[5, 3, 1], [5, 5,...

Python使用add_subplot与subplot画子图操作示例

Python使用add_subplot与subplot画子图操作示例

本文实例讲述了Python使用add_subplot与subplot画子图操作。分享给大家供大家参考,具体如下: 子图:就是在一张figure里面生成多张子图。 Matplotlib对象...

python实现指定字符串补全空格、前面填充0的方法

Python zfill()方法返回指定长度的字符串,原字符串右对齐,前面填充0。 zfill()方法语法:str.zfill(width) 参数width -- 指定字符串的长度。原字...

python3常用的数据清洗方法(小结)

python3常用的数据清洗方法(小结)

首先载入各种包: import pandas as pd import numpy as np from collections import Counter from sklear...