gpt4 book ai didi

python - turtle 创建了一个额外的屏幕(不需要)

转载 作者:行者123 更新时间:2023-12-01 05:43:52 25 4
gpt4 key购买 nike

我让屏幕有一个 Canvas ,里面有一些图画。我还制作了一个制作 turtle 并移动它的函数。问题是当创建 turtle 时,它还创建了一个新窗口, turtle 在其中移动。我不想要第二个窗口。有没有办法移动 turtle 并使其出现在 Canvas 上而不创建第二个窗口?

这是函数:

def Mueve_Carro(type):

color = StringVar

if tipoCarro == 1:
type = "blue"
elif tipoCarro == 2:
type = "orange"
elif tipoCarro == 3:
type = "brown"

ball = Turtle()
ball.penup()
ball.shape("circle")
ball.shapesize(1,1,1)
ball.color(type)
ball.goto(-60,22)

最佳答案

您使用的 Turtle() 类将始终自动创建一个新 Canvas 。您必须使用 RawTurtle(canvas) ,其中 canvas 变量是您在此函数外部创建的屏幕(因此您还需要将其作为参数传递)

所以基本上

def Mueve_Carro(type, canvas):

#...

ball = RawTurtle(canvas)

#...

尽管顾名思义,除了 Canvas 的创建之外,RawTurtleTurtle 之间没有其他区别。

关于python - turtle 创建了一个额外的屏幕(不需要),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16764689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com