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实现两个经纬度点之间的距离和方位角的方法

最近做有关GPS轨迹上有关的东西,花费心思较多,对两个常用的函数总结一下,求距离和求方位角,比较精确,欢迎交流! 1. 求两个经纬点的方位角,P0(latA, lonA), P1(la...

Python 查看文件的编码格式方法

在读取中文的情况下,通常会遇到一些编码的问题,但是首先需要了解目前的编码方式是什么,然后再用decode或者encode去编码和解码,下面是使用chardet库来查看编码方式的。 i...

python 划分数据集为训练集和测试集的方法

sklearn的cross_validation包中含有将数据集按照一定的比例,随机划分为训练集和测试集的函数train_test_split from sklearn.cross_...

python代码打印100-999之间的回文数示例

python代码打印100-999之间的回文数示例

打印100-999之间的回文数(即百位和个位的数字相等),并每10个打印一行 i = 100 x = 0 # 使用计数器,每10个换行打印 while i <= 999:...

简单介绍Python2.x版本中的cmp()方法的使用

 cmp()方法比较两个列表的元素。 语法 以下是cmp()方法的语法: cmp(list1, list2) 参数     lis...