-2

I am working on a project that involves turtles. And I have been trying to find a way to make the turtle start at the bottom left of my screen, as opposed to the coordinates (0,0).

#My Code
import turtle
turtle.setworldcoordinates(-1, -1, 20, 20)

turtle.fd(250)
turtle.rt(90)
turtle.fd(250)

When I tried looking for solutions, I came across a thread "Python turtle set start position" that suggested multiple ways to solve the problem, such as the turtle.setworldcoordinates(-1, -1, 20, 20) references in my code. If anyone has an idea or a soltion, could they please let me know.

James Z
  • 12,209
  • 10
  • 24
  • 44
Kermit
  • 3
  • 1
  • 4
  • Does 'turtle.setworldcoordinates()' not work? – PythonNerd Nov 27 '19 at 14:23
  • The turtle does not start at the very bottom left of the screen. – Kermit Nov 27 '19 at 14:29
  • You are moving forward 250 units in a space with a length of 21. Try using `turtle.fd(19)` – Jona Nov 27 '19 at 14:34
  • If it didn't start at the bottom of the screen, why didn't you just change the coordinates in 'setworldcoordinates' until you got it? – PythonNerd Nov 27 '19 at 14:37
  • That's what I am trying, right now. I am sorry for question. I needed to investigate more. Nevertheless, I have discovered a couple things, for example, 'turtle.setworldcoordinates(-1, -1, 20, 20)' The 20 is the world/canvas size. Also, that I need to find where the start of the grid is. – Kermit Nov 27 '19 at 14:41
  • 1
    (0, 0) are the coordinates. – PythonNerd Nov 27 '19 at 15:03

2 Answers2

1
from turtle import Screen, Turtle

screen = Screen()
screen.setworldcoordinates(-1, -1, screen.window_width() - 1, screen.window_height() - 1)

turtle = Turtle('turtle')

# work with your turtle here

screen.exitonclick()

enter image description here

Depending on the system, and the corner, the -1 constants may need to be as high as -10 to account for the turtle's center position when showing its entire body.

Your follow on code makes little sense:

turtle.fd(250)
turtle.rt(90)
turtle.fd(250)

As the turtle starts out heading to the right and the subsequent right turn, of a turtle in the lower left corner, will take it off the screen.

cdlane
  • 40,441
  • 5
  • 32
  • 81
0

It would help if we knew the size of your turtle.Screen

You can use penup(), goto() methods.

import turtle

wn = turtle.Screen()
wn.setup(width=500, height=500)
wn.tracer(0)
wn.bgcolor('black')

bottom_left = turtle.Turtle()
bottom_left.shape('circle')
bottom_left.color('white')
bottom_left.shapesize(stretch_wid=5, stretch_len=5)
bottom_left.penup()
bottom_left.goto(-250, -250)


while True:
    wn.update()

As you can see I have drawn a 500x500 black grid and placed the turtle to the bottom left based on the grid.

Hope this is something you was looking for, I used this method instead of turtle.setworldcoordinates() method for my games.

As it seem's you want to use setworldcoordinates() I've edited my answer to include a solution for that method too.

import turtle

wn = turtle.Screen()
wn.setup(width=500, height=500)
wn.tracer(0)
wn.bgcolor('black')
wn.setworldcoordinates(-1, -1, 20, 20)

bottom_left = turtle.Turtle()
bottom_left.shape('circle')
bottom_left.color('white')
bottom_left.shapesize(stretch_wid=5, stretch_len=5)


while True:
    wn.update()

Hope this helps...