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并发编程之多进程、多线程、异步和协程详解

最近学习python并发,于是对多进程、多线程、异步和协程做了个总结。 一、多线程 多线程就是允许一个进程内存在多个控制权,以便让多个函数同时处于激活状态,从而让多个函数的操作同时运行...

Win系统PyQt5安装和使用教程

Win系统PyQt5安装和使用教程

安装PyQt5: 安装流程如下: 1.PyQt5下载界面中提供了win32,win64,linux,macos等系统的下载版本,这里我选择的是PyQt5-5.10.1-5.10.1-cp...

Python3.4 tkinter,PIL图片转换

Python3.4 tkinter,PIL图片转换

先给大家分享一下全部代码 import os from PIL import Image import tkinter import tkinter.filedialog impor...

django项目搭建与Session使用详解

django项目搭建与Session使用详解

前言 Django完全支持也匿名会话,简单说就是使用跨网页之间可以进行通讯,比如显示用户名,用户是否已经发表评论。session框架让你存储和获取访问者的数据信息,这些信息保存在服务器上...

python的pip安装以及使用教程

python的pip安装以及使用教程

pip的安装,以及使用pip安装包的方法,记录如下,分享给大家: —–安装python的时候勾选了下载pip,不知道为什么没下载。然后就偷懒想着需要哪个包再单独去下载就好了,然后!!!每...