编程语言
首页 > 编程语言> > 有什么办法可以在Python中用乌龟调整gif形状的大小?

有什么办法可以在Python中用乌龟调整gif形状的大小?

作者:互联网

我正在使用turtle创建一个小游戏,并且意识到可以使用带有turtle.registershape(filename)的图像文件.我知道您可以使用turtle.shapesize或turtle.resizemode(“ auto”)调整默认形状的大小并更改pensize,但是有什么方法可以使用这些方法来调整gif文件的大小吗?

import turtle

turtle.addshape("example.gif")

t = turtle.Turtle()

t.shape("example.gif")

t.resizemode("auto")
t.pensize(24)
t.stamp()

turtle.exitonclick()

我希望像这样的东西工作,但是乌龟会正常显示,而不是调整大小.

解决方法:

我查看了适用的乌龟代码,我相信答案是:“不,不在乌龟本身内.”

引入乌龟基础的tkinter,可以给我们提供一些有限的(整体)乌龟图像扩展和缩小功能:

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()

如果需要更大的灵活性,标准方法似乎是在Turtle / tkinter外部调整图形大小或使用PIL模块动态调整图形大小并将其移交给turtle / tkinter.

标签:turtle-graphics,python,python-2-7,gif
来源: https://codeday.me/bug/20191013/1905144.html