在 python 中使用外部图像

Using external image in python

我正在使用 turtle 图形库制作简单的应用程序。

我试过做.bgpic,但是好像走的不是我想要的。

我将图像放在 python 源文件所在的同一目录中,我这样做了:

screen = turtle.Screen()
screen.bgpic("picture.png")

但它并没有改变任何东西。当我 运行 它时,它只有白色背景。

我该怎么办?

图片必须是 gif 文件,doc

turtle.bgpic(picname=None)

Parameters: picname – a string, name of a gif-file or "nopic", or None

Set background image or return name of current backgroundimage. If picname is a filename, set the corresponding image as background. If picname is "nopic", delete background image, if present. If picname is None, return the filename of the current backgroundimage.

picture.gif

import turtle

screen = turtle.Screen()
screen.bgpic("picture.gif")
turtle.done()