我在linux膝上型计算机(Ubuntu)上编写了这段代码,但现在,当我试图在mac上运行它时,我得到了错误:
_tkinter.TclError: couldn't recognize data in image file "background.png"
在我的图形init函数中试图将图像设置为背景时,就会发生这种情况。
def __init__(self):
self.window = turtle.Screen()
self.window.setup(724, 724)
self.window.bgpic("background.png")
self.window.tracer(0, 0)
发布于 2017-12-15 15:52:56
根据https://docs.python.org/3/library/turtle.html#turtle.bgpic的说法,背景图片必须是一个GIF。不支持PNG。但是您可以使用PIL/Pillow ()或NumPy动态地将PNG转换为GIF。
https://stackoverflow.com/questions/47835643
复制相似问题