The turtle
module does have support for images, but only GIF images, not PNG or any other format. As the docs for addshape
say:
name is the name of a gif-file and shape is None
: Install the corresponding image shape.
And if you look at the source, they're serious about "gif-file": the way it decides whether you're trying to add an image or a polygon is by calling data.lower().endswith(".gif")
, which obviously won't work for .png
files.
And, even if you fix that, it will still only be able to handle the file formats that Tkinter
supports out of the box, which includes some extra things like PPM/PGM/PBM, but still not PNG. If you want to support PNG files, you'll want to install Pillow
as well.
At this point, you're getting beyond what people usually do with turtle
. That might be worth pursuing (you'll learn a lot by doing so), but it may be simpler to use an image-converting program to convert the .png
file to a .gif
file so it will work with your existing code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…