python - 在 Turtle 模块中使用 PNG

标签 python python-3.x pillow

我正在寻找一种在 Turtle 窗口中将 PNG 用作 Turtle 形状或背景图片的方法。

from PIL import ImageTk, Image
from turtle import *

t = Turtle()
img = ImageTk.PhotoImage(Image.open("Turtle.png"))
register_shape("Pic", Shape("image", img))
t.shape(img)

当我开始这段代码时,我总是得到这个错误代码:

raise TurtleGraphicsError("There is no shape named %s" % name)
turtle.TurtleGraphicsError: There is no shape named pyimage2

我听说您可以使用 PIL.ImageTk.PhotoImage(Image.open()) 在 python 代码中使用 PNG 一些想法如何让这段代码工作? 使用 Python 3.6.4

最佳答案

关于python - 在 Turtle 模块中使用 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50861142/

相关文章:

python - 如何评价均方误差(MSE)是否合理?

python - 我不明白 Python (2.7.3) 中的编码和解码

python-3.x - 与 aiohttp 应用程序内的 Redis(aioredis) 失去连接

python - 如何从 Python 中的 pandas 数据框中获取 networkx 图的分支作为列表?

pillow - 属性错误 : 'module' object has no attribute 'Number'

python - 忽略...参数在 `__init__` 的层必须覆盖 `get_config`

python - 使用 pandas 读取 csv 时获取坏行/错误的数量 ( error_bad_lines)

python : ENUM class elements are not reachable for built-in dir() function

python-3.x - Python 3,PIL 是 Pillow 的别名吗?

python - 如何使用 pip 在 Windows 上安装 Pillow?