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中关键字is与==的区别简述

本文以简单示例分析了python中关键字is与 ==的区别,供大家参考一下。 首先说明一下Python学习中几个相关的小知识点。 Python中的对象包含三要素:id、type、valu...

Python分支语句与循环语句应用实例分析

本文实例讲述了Python分支语句与循环语句应用。分享给大家供大家参考,具体如下: 一、分支语句 1、if else语句 语法: if 条件判断: 执行的语句块1 else :...

TensorFlow模型保存/载入的两种方法

TensorFlow 模型保存/载入 我们在上线使用一个算法模型的时候,首先必须将已经训练好的模型保存下来。tensorflow保存模型的方式与sklearn不太一样,sklearn很直...

Python中字符编码简介、方法及使用建议

1. 字符编码简介 1.1. ASCII ASCII(American Standard Code for Information Interchange),是一种单字节的编码。计算机世...

PyQT5 emit 和 connect的用法详解

PyQT5 emit 和 connect的用法详解

对于PyQT4, PyQT5在一些使用上有着比较明显的变化有很大的变化,让人惊讶是在emit和connect上的一些变化比较有意思,相信也是QT为了更好的和Python相结合做的改进。...