Turtle text and stamps: write(), shape() and stamp()
write() puts text on the turtle window, shape() changes what the turtle
looks like, and stamp() leaves a copy of that shape behind.
Write text
import turtle
t = turtle.Turtle()
t.write("Hello!")
t.forward(80)
The text starts at the turtle and uses the pen colour. Writing does not move the turtle.
Choose the alignment and font
align is "left" (the default), "center" or "right". font is a group of
three: a font name, a size and a style ("normal", "bold" or "italic").
import turtle
t = turtle.Turtle()
t.pencolor("blue")
t.write("Agent Games", align="center", font=("Arial", 24, "bold"))
t.hideturtle()
hideturtle() hides the turtle itself, so only the text is left. showturtle()
brings it back.
Change the turtle's shape
shape(name) picks how the turtle looks: "arrow", "turtle", "circle",
"square", "triangle" or "classic", the default.
import turtle
t = turtle.Turtle()
t.shape("turtle")
t.forward(100)
print(t.shape())
Leave copies with stamp()
stamp() prints a copy of the turtle's shape onto the window. The copy stays
when the turtle moves on.
import turtle
t = turtle.Turtle()
t.shape("turtle")
t.penup()
t.stamp()
t.forward(60)
t.stamp()
t.forward(60)
Two stamps, and the turtle itself at the end. clearstamps() removes every
stamp.
See also: Turtle colours, The turtle screen.
Your turn
Add three lines: change the shape to "square", stamp it, then hide the
turtle.
import turtle
t = turtle.Turtle()
t.penup()
# add three lines: change the shape to "square", stamp, then hide the turtle
print(t.shape())
print(t.isvisible())
Expected output
square
False