Jump to content

How do I make the turtle go to the edge of the screen in python?

DietzDiet
Go to solution Solved by Sauron,

The screen has a border that covers part of the edges and since the position is relative to the center of the sprite it's hidden by the border when you send it right to the edge. Just send it to -240 or so instead.

 

If you want to better understand what's happening I suggest you try the live interpreter instead of running the whole script. This will let you try different numbers and realize what you're doing wrong. It will get you a lot farther and a lot faster than just asking here for every tiny problem.

How do I make the turtle go to the edge of the screen in python? I am trying to do that but it goes off screen every time 😞
 

from turtle import Turtle, Screen

screen = Screen()

screen.setup(width=500, height=400)
answer = screen.textinput(title="Choose Your Turtle", prompt="Which turtle do you think will win? Red, Green, Blue , Yellow, or Pink!")

tim = Turtle()

tim.penup()

tim.goto(x=-250, y=0)
tim.showturtle()
tim.pendown()

screen.exitonclick()

 

Link to comment
Share on other sites

Link to post
Share on other sites

The screen has a border that covers part of the edges and since the position is relative to the center of the sprite it's hidden by the border when you send it right to the edge. Just send it to -240 or so instead.

 

If you want to better understand what's happening I suggest you try the live interpreter instead of running the whole script. This will let you try different numbers and realize what you're doing wrong. It will get you a lot farther and a lot faster than just asking here for every tiny problem.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Your problem is using goto with a negative number.

 

Turtle coordinates start with (0, 0) in the top left corner, and go to (width, height) in the bottom right corner. Increasing x goes right, decreasing goes left, increasing y goes down, decreasing goes up. So in your case goto(-250, 0) means go to 250 pixels left of the top left corner, which is off the screen.

 

Nope. Totally wrong. I was thinking of another similar library.

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 | Fractal Design Meshify C | Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×