Is there any way to resize a gif shape with turtle in Python?

廉价感情. 提交于 2019-12-02 08:06:05

I reviewed the applicable turtle code and I believe the answer is, "No, not within turtle itself."

Bringing in tkinter, which underlies turtle, gives us some limited (integral) turtle image expansion and reduction capability:

from tkinter import PhotoImage
from turtle import Turtle, Screen, Shape

screen = Screen()

# substitute 'subsample' for 'zoom' if you want to go smaller:
larger = PhotoImage(file="example.gif").zoom(2, 2)

screen.addshape("larger", Shape("image", larger))

tortoise = Turtle("larger")

tortoise.stamp()

tortoise.hideturtle()

screen.exitonclick()

If you want more flexibility, the standard approach seems to be to either resize the graphic outside of turtle/tkinter or use the PIL module to resize the graphic dynamically and hand it to turtle/tkinter.

The answer is no. I went through the source code of cpython library and tracked to the draw image method call. See _drawturtle method of cpython library, where drawImage method is called with no information of variables like pensize or shapesize. I agree with @cdlane that you will have to use other resize using other libraries, however one tip, if you know beforehand the set of image sizes you will need, you can generate them and load during the game start instead of resizing at the runtime.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!