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获取Linux发行版名称

我必须从Python脚本中获取Linux发行版名称。dist平台模块中有一个方法: import platform platform.dist() 但在我的Arch Linux下...

python如何解析配置文件并应用到项目中

配置文件的类型 通常自动化测试中的配置文件是以.ini 和 .conf 为后缀的文件 配置文件的组成 1.section 2.option 3.value 配置文件的格式 [s...

Django Docker容器化部署之Django-Docker本地部署

Django Docker容器化部署之Django-Docker本地部署

本章将在本地搭建一个容器化的 Django 项目,感受 Docker 的运作方式。 前期准备 开发环境 虽然有基于 Windows 的 Docker 版本,但各方面兼容做得都不太好(...

详解python基础之while循环及if判断

 wlile循环   while True表示永远为真,不管是什么条件都会向下执行,下面是写的一个例子。 #!/usr/bin/env python age = 24        ...

django站点管理详解

管理界面是基础设施中非常重要的一部分。这是以网页和有限的可信任管理者为基础的界面,它可以让你添加,编辑和删除网站内容。Django有自己的自动管理界面。这个特性是这样起作用的:它读取你模...