我正在寻找一种在 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
最佳答案
您必须指定注册图像时使用的名称。试试这个:
t.shape("Pic")
引用:
关于python - 在 Turtle 模块中使用 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50861142/