【问题标题】:AttributeError: 'Turtle' object has no attribute 'shapesize' on line 14AttributeError: 'Turtle' 对象在第 14 行没有属性 'shapesize'
【发布时间】:2020-07-12 15:56:14
【问题描述】:

我正在尝试在 Repl.it 上制作海龟游戏,但我不知道为什么这个错误不断出现。这是我的代码:

import turtle

wn = turtle.Screen()
wn.bgcolor("white")
wn.setup(width=800, height=800)
wn.tracer(0)

# Set up the ground

ground = turtle.Turtle()
ground.color("white")
ground.shape("square")
ground.speed(0)
ground.shapesize(stretch_wid=200, stretch_len=20)
ground.speed(0)
ground.color("black")
ground.penup()
ground.goto(0, -400)
ground.direction = "stop"

【问题讨论】:

  • 我的回复对您有帮助吗?如果是这样,请将答案标记为已接受:)

标签: python object import attributes attributeerror


【解决方案1】:

repl.it 上的 turtle 库的实现似乎有些受限,并非所有命令都可用。您可以在本地运行它以使用所有命令或删除不兼容的命令。

来源:https://repl.it/talk/ask/Turtle-python-resizing/7312

【讨论】:

    【解决方案2】:

    实际上有一种方法可以做到这一点。 每当您创建一个新的 repl 而不是创建“带有龟的 python”repl 时,只需创建一个普通的 python 。然后导入 turtle 模块,它应该可以工作。在基本的 python 文件中导入它时,它会导入所有内容。 每当您执行import turtle 时,添加from turtle import * 也是一个好主意,这样您就可以导入所有内容。

    【讨论】:

      【解决方案3】:

      我也有这个问题 您可以将 Python 与 pygame 一起使用,而不是将 python 与 turtle 一起使用,因为出于某种原因,它可以工作

      【讨论】:

      • Pygame 是一个完全不同的库,与 turtle 不兼容
      猜你喜欢
      • 2018-10-16
      • 2020-06-20
      • 2021-11-09
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      相关资源
      最近更新 更多