属性错误:"Turtle"对象在第 14 行没有属性"shapesize"



我正试图在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"

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

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

实际上有一种方法可以做到这一点。每当你创建一个新的repl而不是创建一个"repl"时;蟒蛇配乌龟;repl只是创建一个普通的python。然后导入乌龟模块,它应该可以工作了。当在基本的python文件上导入它时,它会导入所有内容。无论何时执行import turtle,都最好以导入所有内容的方式添加from turtle import *

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

最新更新