【问题标题】:Python: Making Background Image with TurtlesPython:用海龟制作背景图像
【发布时间】:2012-09-20 13:15:06
【问题描述】:

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

这是当前代码:

from turtle import * 
from Tkinter import *

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

【问题讨论】:

  • 添加您遇到问题的代码,以及您收到的任何错误消息,这将使这里的人们更容易为您提供帮助。
  • 创建一个完整的最小示例来重现错误和edit 您的问题,以包括您收到的代码和错误,例如,运行import turtle; turtle.bgpic('your.gif') 并报告任何错误。

标签: python background-image turtle-graphics


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 2020-03-02
    • 1970-01-01
    • 2022-01-23
    • 2020-10-15
    • 2014-03-18
    • 2018-12-07
    相关资源
    最近更新 更多