PyDocs

Graphical user interfaces with Tk

turtle

Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an import turtle, give it the command turtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.right(25), and it rotates in-place 25 degrees clockwise.
Symbols in turtle

a

addshape
Add a turtle shape to the TurtleScreen’s shape list.

b

back
Move the turtle backward by distance, opposite to the direction the turtle is headed.
backward
Move the turtle backward by distance, opposite to the direction the turtle is headed.
begin_fill
To be called just before drawing a shape to be filled.
begin_poly
Start recording the vertices of a polygon.
bgcolor
Return or set the background color of the TurtleScreen.
bgpic
Set background image or return name of current backgroundimage.
bk
Move the turtle backward by distance, opposite to the direction the turtle is headed.
bye
Close the turtle graphics window.

c

circle
Draw a circle with the given radius.
clear
Delete the turtle’s drawings from the screen.
clearscreen
Delete all drawings and all turtles from the TurtleScreen.
clearstamp
Delete stamp with given stampid.
clearstamps
Delete all or first/last n of turtle’s stamps.
clone
Create and return a clone of the turtle.
color
Return or set the pencolor and fillcolor.
colormode
Return the colormode or set it to 1.0 or 255.

d

degrees
Set the angle measurement units to degrees.
delay
Return or set the drawing delay in milliseconds.
distance
Return the distance from the turtle to (x,y) in turtle step units.
done
Start the event loop by calling Tkinter’s mainloop() method.
dot
Draw a circular dot with diameter size, using color.
down
Lower the pen.

e

end_fill
Fill the shape drawn after the last call to begin_fill().
end_poly
Stop recording the vertices of a polygon.
exitonclick
Bind bye() method to mouse clicks on the Screen.

f

fd
Move the turtle forward by the specified distance, in the direction the turtle is headed.
fill
Fill the shape drawn in the with turtle.fill(): block.
fillcolor
Return or set the fillcolor.
filling
Return True if the turtle is filling, False otherwise.
forward
Move the turtle forward by the specified distance, in the direction the turtle is headed.

g

get_poly
Return the last recorded polygon.
get_shapepoly
Return the current shape polygon as tuple of coordinate pairs.
getcanvas
Return the Canvas of this TurtleScreen.
getpen
Return the Turtle object itself.
getscreen
Return the TurtleScreen object the turtle is drawing on.
getshapes
Return a list of names of all currently available turtle shapes.
getturtle
Return the Turtle object itself.
goto
Move the turtle to an absolute position.

h

heading
Return the turtle’s current heading.
hideturtle
Make the turtle invisible.
home
Move the turtle to the origin, coordinates (0,0).
ht
Make the turtle invisible.

i

isdown
Return True if the pen is down, False if it’s up.
isvisible
Return True if the turtle is visible, False if it’s hidden.

l

left
Turn the turtle left by the specified angle.
listen
Set focus on TurtleScreen (in order to collect key-events).
lt
Turn the turtle left by the specified angle.

m

mainloop
Start the event loop by calling Tkinter’s mainloop() method.
mode
Set the turtle mode and perform a reset.

n

no_animation
Temporarily turn off turtle animation.
numinput
Pop up a dialog window for input of a number.

o

onclick
Bind fun to mouse-click events on this screen.
ondrag
Bind fun to mouse-move events on this turtle.
onkey
Bind fun to key-release event of key.
onkeypress
Bind fun to key-press event of key if key is given, or to any key-press-event if no key is given.
onkeyrelease
Bind fun to key-release event of key.
onrelease
Bind fun to mouse-button-release events on this turtle.
onscreenclick
Bind fun to mouse-click events on this screen.
ontimer
Install a timer that calls fun after t milliseconds.

p

pd
Lower the pen.
pen
Return or set the pen’s attributes in a “pen-dictionary” with the following key/value pairs:
pencolor
Return or set the pencolor.
pendown
Lower the pen.
pensize
Return or set the line thickness.
penup
Lift the pen.
poly
Record the vertices of a polygon drawn in the with turtle.poly(): block.
pos
Return the turtle’s current location (x,y) as a Vec2D vector.
position
Return the turtle’s current location (x,y) as a Vec2D vector.
pu
Lift the pen.

r

radians
Set the angle measurement units to radians.
RawPen
Create a turtle.
RawTurtle
Create a turtle.
register_shape
Add a turtle shape to the TurtleScreen’s shape list.
reset
Delete the turtle’s drawings and re-center the turtle.
resetscreen
Reset all turtles on the screen to their initial state.
resizemode
Set the resizemode to “auto”, “user” or “noresize”.
right
Turn the turtle right by the specified angle.
rt
Turn the turtle right by the specified angle.

s

save
Save the current turtle drawing (and turtles) as a PostScript file.
Screen
Subclass of TurtleScreen, with four methods added.
screensize
If no arguments are given, return current (canvaswidth, canvasheight).
ScrolledCanvas
Used by class Screen, which thus automatically provides a ScrolledCanvas as playground for the turtles.
seth
Set the turtle’s heading to to_angle.
setheading
Set the turtle’s heading to to_angle.
setpos
Move the turtle to an absolute position.
setposition
Move the turtle to an absolute position.
setundobuffer
Set or disable the undo buffer.
setup
Set the size and position of the main window.
setworldcoordinates
Set up a user-defined coordinate system.
setx
Set the turtle’s x coordinate to x.
sety
Set the turtle’s y coordinate to y.
shape
Set the turtle shape to the named shape.
Shape
Data structure modeling shapes.
shapesize
Return or set the turtle’s stretch factors and outline width.
shapetransform
Set or return the current transformation matrix of the turtle shape.
shearfactor
Set or return the current shearfactor.
showturtle
Make the turtle visible.
speed
Return or set the turtle’s speed.
st
Make the turtle visible.
stamp
Stamp a copy of the turtle shape onto the canvas at the current turtle position.

t

teleport
Teleport, or instantly move, the turtle to an absolute position.
textinput
Pop up a dialog window for input of a string.
tilt
Rotate the turtleshape by angle from its current tilt-angle, but do not change the turtle’s heading (direction of movement).
tiltangle
Set or return the current tilt-angle.
title
Set the title of the turtle window to titlestring.
towards
Return the angle of the line from the turtle’s position to (x,y).
tracer
Turn turtle animation on or off and set the drawing delay.
Turtle
Subclass of RawTurtle, has the same interface but draws on a default Screen object created automatically when needed for the first time.
TurtleGraphicsError
Raised for invalid arguments or operations.
turtles
Return the list of turtles on the screen.
TurtleScreen
Provides screen oriented methods like bgcolor() etc.
turtlesize
Return or set the turtle’s stretch factors and outline width.

u

undo
Undo (repeatedly) the last turtle action(s).
undobufferentries
Return the number of entries in the undo buffer.
up
Lift the pen.
update
Perform a TurtleScreen update.

v

Vec2D
A two-dimensional vector class, used as a helper class for implementing turtle graphics.

w

width
Return or set the line thickness.
window_height
Return the height of the turtle window.
window_width
Return the width of the turtle window.
write
Write text - the string representation of arg - at the current turtle position according to align (“left”, “center” or “right”) and with the given font.
write_docstringdict
Create and write docstring-dictionary to a Python script with the given filename.

x

xcor
Return the turtle’s x coordinate.

y

ycor
Return the turtle’s y coordinate.