gpt4 book ai didi

How can i find the corodinates of a point in python's "Turtle" library?(如何在Python的“Turtle”库中找到点的坐标?)

转载 作者:bug小助手 更新时间:2023-10-24 19:45:28 27 4
gpt4 key购买 nike



I want to make a shape using python's Turtle library and to do so, i have to find the corodinates of the center of my shape and then use the goto() command. Is this possible to do it?

我想要使用Python的Turtle库创建一个形状,为此,我必须找到形状中心的Corodinate,然后使用goto()命令。这有可能做到吗?


And also I tried to reach the center with moving the turtle instead of using the goto() command but it is not possible or i am doing something wrong. Some help would be really apperciated!

此外,我试图通过移动乌龟而不是使用goto()命令到达中心,但这是不可能的,或者我做错了什么。一些帮助真的会很受欢迎!


更多回答

Can you share your code? I'm confused: if you want to create a shape, it doesn't exist yet and you get to choose the center, right?

你能分享你的代码吗?我很困惑:如果你想创建一个形状,它还不存在,你可以选择中心,对吗?

优秀答案推荐

Can you please share your code?

你能分享一下你的代码吗?



  1. If you are trying to find the current position of your turtle shape on screen use turtle.pos()


from turtle import Turtle, Screen
import random as rnd

screen = Screen()
my_shape = Turtle(shape='turtle')
my_shape.penup()
my_shape.goto(x=rnd.randint(1, 50), y=rnd.randint(1, 50)) # send turtle to random position ve+ x and ve+ y coordinate
curr_pos = my_shape.pos() # get current turtle position by turtle.pos() method
print(f"current position: {curr_pos}")
screen.exitonclick()

output--> current position: (45.00,5.00)

输出-->当前位置:(45.00,5.00)



  1. If you are trying to bring back your shape in center screen use turtle.home()


from turtle import Turtle, Screen
import random as rnd

screen = Screen()
my_shape = Turtle(shape='turtle')
my_shape.penup()
my_shape.goto(x=rnd.randint(1, 50), y=rnd.randint(1, 50)) # send turtle to random position ve+ x and ve+ y coordinate
curr_pos = my_shape.pos() # get current turtle position by turtle.pos() method
print(f"current position: {curr_pos}")
my_shape.home() # send turtle to home position (0,0)
home_pos = my_shape.pos()
print(f"Home position: {home_pos}")
screen.exitonclick()

output--> current position: (48.00,41.00) Home position: (0.00,0.00)

输出-->当前位置:(48.00,41.00)主页位置:(0.00,0.00)


更多回答

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