Python:用乌龟制作背景图像

时间:2012-09-20 13:15:07

标签: python background-image turtle-graphics

我正试图在我的海龟世界中插入一个.gif文件作为背景图像,以便让一只单独的海龟旅行,但我无法让它工作。我是python的新手,任何帮助都会很棒。

这是当前的代码:

from turtle import * 
from Tkinter import *

def test():
    turtle.bgpic("warehouse1.gif")
    fd(100)
    goto(50, 100)

1 个答案:

答案 0 :(得分:2)

from turtle import *turtle模块中提供所有名称,因此在这种情况下您可以使用裸bgpic()

#!/usr/bin/env python
from turtle import *

def test():
    speed(1) # set the slowest speed to see the turtle movements
    bgpic('warehouse1.gif')
    fd(100)
    goto(50, 100)
    mainloop()

test()

注意:通常,不应在Python交互式shell之外使用通配符导入(*)。请参阅Idioms and Anti-Idioms in Python

相关问题