Python Turtle 模块 - 保存图像 [英] Python Turtle Module- Saving an image

查看:106
本文介绍了Python Turtle 模块 - 保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何在使用python的turtle模块创建绘图后保存位图或矢量图形图像.经过一番谷歌搜索后,我找不到一个简单的答案.我确实找到了一个名为 canvas2svg 的模块,但我对 python 很陌生,我不知道如何安装模块.是否有一些内置的方法来保存海龟画布的图像?如果不是,我应该将 Python 的自定义模块放在 Ubuntu 机器上的什么位置?

I would like to figure out how to save a bitmap or vector graphics image after creating a drawing with python's turtle module. After a bit of googling I can't find an easy answer. I did find a module called canvas2svg, but I'm very new to python and I don't know how to install the module. Is there some built in way to save images of the turtle canvas? If not where do I put custom modules for python on an Ubuntu machine?

推荐答案

from Tkinter import *
from turtle import *
import turtle


forward(100)
ts = turtle.getscreen()

ts.getcanvas().postscript(file="duck.eps")

这会帮助你;我也遇到了同样的问题,我google了一下,但是通过阅读turtle模块的源码解决了.

This will help you; I had the same problem, I Googled it, but solved it by reading the source of the turtle module.

canvas(tkinter)对象有postscript功能;你可以使用它.

The canvas (tkinter) object has the postscript function; you can use it.

海龟模块具有getscreen",它为您提供海龟屏幕",为您提供海龟正在其中绘制的 Tiknter 画布.

The turtle module has "getscreen" which gives you the "turtle screen" which gives you the Tiknter canvas in which the turtle is drawing.

这会将您保存为封装的 PostScript 格式,因此您肯定可以在 GIMP 中使用它,但也有其他查看器.或者,您可以谷歌如何从中制作 .gif.

This will save you in encapsulated PostScript format, so you can use it in GIMP for sure but there are other viewers too. Or, you can Google how to make a .gif from this.

这篇关于Python Turtle 模块 - 保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆