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程序设计有所帮助。

相关文章

利用pytorch实现对CIFAR-10数据集的分类

步骤如下: 1.使用torchvision加载并预处理CIFAR-10数据集、 2.定义网络 3.定义损失函数和优化器 4.训练网络并更新网络参数 5.测试网络 运行环境: win...

python利用datetime模块计算时间差

今天写了点东西,要计算时间差,我记得去年写过,于是今天再次mark一下,以免自己忘记 In [27]: from datetime import datetime In [28]:...

Python中偏函数用法示例

本文实例讲述了Python中偏函数用法。分享给大家供大家参考,具体如下: python中偏函数 当一个函数有很多参数时,调用者就需要提供多个参数。如果减少参数个数,就可以简化调用者的负...

Python实现多进程的四种方式

方式一: os.fork() # -*- coding:utf-8 -*- """ pid=os.fork() 1.只用在Unix系统中有效,Windows系统中无效 2.f...

Python使用turtule画五角星的方法

本文实例讲述了Python使用turtule画五角星的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python import turtle impo...