Tuesday, August 11, 2020

Python turtle set start position


I'll give you my solution for starting at the top left of the window and you can adjust it to your needs:
 
 
from turtle import Turtle, Screen

TURTLE_SIZE = 20

screen = Screen()

yertle = Turtle(shape="turtle", visible=False)
yertle.penup()
yertle.goto(TURTLE_SIZE/2 - screen.window_width()/2, screen.window_height()/2 - TURTLE_SIZE/2)
yertle.pendown()
yertle.showturtle()

screen.mainloop()


The turtle's first appearance should be at the top left of the window.



Python turtle, change start position:
import turtle
a = turtle.Turtle()      #instantiate a new turtle object called 'a'
a.hideturtle()           #make the turtle invisible
a.penup()                #don't draw when turtle moves
a.goto(-200, -200)       #move the turtle to a location
a.showturtle()           #make the turtle visible
a.pendown()              #draw when the turtle moves
a.goto(50, 50)           #move the turtle to a new location
The turtle becomes visible and starts drawing at position -200, -200 and goes to 50, 50.

No comments:

Post a Comment

Introduction to Keras and TensorFlow for Training Deep Learning Classifiers

 ### Introduction to Keras and TensorFlow for Training Deep Learning Classifiers **Keras and TensorFlow** are powerful tools in the realm of...