【发布时间】:2017-12-15 15:45:14
【问题描述】:
我在 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)
【问题讨论】:
-
我在基于 Ubuntu 16 的 Linux Mint 18.2 上的 Python 2.7.12 上使用
bgpic()测试了您的图像,它可以工作。turtle是基于tkinter构建的,它默认只支持gif,所以在turtle中也可能有问题。模块PIL/pillow中有一个特殊的类可以将png(和其他格式)与tkinter一起使用。我已经安装了pillow,如果没有pillow,我无法检查bgpic是否有问题。你可以尝试安装pillow。
标签: python python-2.7 turtle-graphics