Turtle - Turtle Graphics - Python 3.9.7 Documentation
Turtle - Turtle Graphics - Python 3.9.7 Documentation
Introduction
Turtle graphics is a popular way for introducing programming to kids. It was
part of the original
Logo programming language developed by Wally Feurzeig,
Seymour Papert and Cynthia Solomon
in 1967.
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.
The turtle module is an extended reimplementation Turtle can draw intricate shapes using
of the same-named
module from the Python standard programs that repeat simple
moves.
distribution up to version Python 2.5.
while True:
if abs(pos()) < 1:
a
ScrolledCanvas as argument. It should be end_fill()
application.
The function Screen() returns a singleton object of a
TurtleScreen subclass. This function
should be used when
turtle is used as a standalone tool for doing graphics.
As a singleton
object, inheriting from its class is not possible.
The procedural interface provides functions which are derived from the methods
of the classes
Screen and Turtle . They have the same names as
the corresponding methods. A screen object is
automatically created whenever a
function derived from a Screen method is called. An
(unnamed) turtle object is
automatically created whenever any of the functions derived from a
Turtle method
is called.
To use multiple turtles on a screen one has to use the object-oriented interface.
Note:
In the following documentation the argument list for functions is given.
Methods, of
course, have the additional first argument self which is
omitted here.
forward() | fd()
backward() | bk() | back()
right() | rt()
left() | lt()
goto() | setpos() | setposition()
setx()
sety()
setheading() | seth()
home()
circle()
dot()
stamp()
clearstamp()
clearstamps()
undo()
speed()
position() | pos()
towards()
xcor()
ycor()
heading()
distance()
degrees()
radians()
Pen control
Drawing state
Color control
color()
pencolor()
fillcolor()
Filling
filling()
begin_fill()
end_fill()
reset()
clear()
write()
Turtle state
Visibility
showturtle() | st()
hideturtle() | ht()
isvisible()
Appearance
shape()
resizemode()
shapesize() | turtlesize()
shearfactor()
settiltangle()
tiltangle()
tilt()
shapetransform()
get_shapepoly()
Using events
onclick()
onrelease()
ondrag()
begin_poly()
end_poly()
get_poly()
clone()
getturtle() | getpen()
getscreen()
setundobuffer()
undobufferentries()
Methods of TurtleScreen/Screen
Window control
bgcolor()
bgpic()
clearscreen()
resetscreen()
screensize()
setworldcoordinates()
Animation control
delay()
tracer()
update()
mode()
colormode()
getcanvas()
getshapes()
register_shape() | addshape()
turtles()
window_height()
window_width()
Input methods
textinput()
numinput()
bye()
exitonclick()
setup()
title()
Turtle motion
turtle. forward(distance)
turtle. fd(distance)
Move the turtle forward by the specified distance, in the direction the
turtle is headed.
>>> turtle.position()
(0.00,0.00)
>>> turtle.forward(25)
>>> turtle.position()
(25.00,0.00)
>>> turtle.forward(-75)
>>> turtle.position()
(-50.00,0.00)
turtle. back(distance)
turtle. bk(distance)
turtle. backward(distance)
>>> turtle.position()
(0.00,0.00)
>>> turtle.backward(30)
>>> turtle.position()
(-30.00,0.00)
turtle. right(angle)
turtle. rt(angle)
Turn turtle right by angle units. (Units are by default degrees, but
can be set via the degrees()
and radians() functions.) Angle
orientation depends on the turtle mode, see mode() .
>>> turtle.heading()
22.0
>>> turtle.right(45)
>>> turtle.heading()
337.0
turtle. left(angle)
turtle. lt(angle)
Turn turtle left by angle units. (Units are by default degrees, but
can be set via the degrees()
and radians() functions.) Angle
orientation depends on the turtle mode, see mode() .
>>> turtle.heading()
22.0
>>> turtle.left(45)
>>> turtle.heading()
67.0
>>> tp = turtle.pos()
>>> tp
(0.00,0.00)
>>> turtle.setpos(60,30)
>>> turtle.pos()
(60.00,30.00)
>>> turtle.setpos((20,80))
>>> turtle.pos()
(20.00,80.00)
>>> turtle.setpos(tp)
>>> turtle.pos()
(0.00,0.00)
turtle. setx(x)
>>> turtle.position()
(0.00,240.00)
>>> turtle.setx(10)
>>> turtle.position()
(10.00,240.00)
turtle. sety(y)
>>> turtle.position()
(0.00,40.00)
>>> turtle.sety(-10)
>>> turtle.position()
(0.00,-10.00)
turtle. setheading(to_angle)
turtle. seth(to_angle)
Set the orientation of the turtle to to_angle. Here are some common
directions in degrees:
>>> turtle.setheading(90)
>>> turtle.heading()
90.0
turtle. home()
Move turtle to the origin – coordinates (0,0) – and set its heading to
its start-orientation
(which depends on the mode, see mode() ).
>>> turtle.heading()
90.0
>>> turtle.position()
(0.00,-10.00)
>>> turtle.home()
>>> turtle.position()
(0.00,0.00)
>>> turtle.heading()
0.0
Draw a circle with given radius. The center is radius units left of
the turtle; extent – an angle –
determines which part of the circle
is drawn. If extent is not given, draw the entire circle. If
extent
is not a full circle, one endpoint of the arc is the current pen
position. Draw the arc in
counterclockwise direction if radius is
positive, otherwise in clockwise direction. Finally the
direction of the
turtle is changed by the amount of extent.
>>> turtle.position()
(0.00,0.00)
>>> turtle.heading()
0.0
>>> turtle.circle(50)
>>> turtle.position()
(-0.00,0.00)
>>> turtle.heading()
0.0
>>> turtle.position()
(0.00,240.00)
>>> turtle.heading()
180.0
>>> turtle.home()
>>> turtle.dot()
>>> turtle.position()
(100.00,-0.00)
>>> turtle.heading()
0.0
turtle. stamp()
Stamp a copy of the turtle shape onto the canvas at the current turtle
position. Return a
stamp_id for that stamp, which can be used to delete
it by calling clearstamp(stamp_id) .
>>> turtle.color("blue")
>>> turtle.stamp()
11
>>> turtle.fd(50)
turtle. clearstamp(stampid)
(150.00,-0.00)
>>> turtle.color("blue")
>>> turtle.fd(50)
>>> turtle.position()
(200.00,-0.00)
>>> turtle.clearstamp(astamp)
>>> turtle.position()
(200.00,-0.00)
turtle. clearstamps(n=None)
13
14
15
16
17
18
19
20
>>> turtle.clearstamps(2)
>>> turtle.clearstamps(-2)
>>> turtle.clearstamps()
turtle. undo()
Undo (repeatedly) the last turtle action(s). Number of available
undo actions is determined
by the size of the undobuffer.
... turtle.undo()
turtle. speed(speed=None)
“fastest”: 0
“fast”: 10
“normal”: 6
“slow”: 3
“slowest”: 1
>>> turtle.speed()
>>> turtle.speed('normal')
>>> turtle.speed()
>>> turtle.speed(9)
>>> turtle.speed()
turtle. position()
turtle. pos()
Return the turtle’s current location (x,y) (as a Vec2D vector).
>>> turtle.pos()
(440.00,-0.00)
Return the angle between the line from turtle position to position specified
by (x,y), the vector
or the other turtle. This depends on the turtle’s start
orientation which depends on the mode -
“standard”/”world” or “logo”.
>>> turtle.towards(0,0)
225.0
turtle. xcor()
Return the turtle’s x coordinate.
>>> turtle.home()
>>> turtle.left(50)
>>> turtle.forward(100)
>>> turtle.pos()
(64.28,76.60)
64.27876
turtle. ycor()
Return the turtle’s y coordinate.
>>> turtle.home()
>>> turtle.left(60)
>>> turtle.forward(100)
>>> print(turtle.pos())
(50.00,86.60)
86.60254
turtle. heading()
Return the turtle’s current heading (value depends on the turtle mode, see
mode() ).
>>> turtle.home()
>>> turtle.left(67)
>>> turtle.heading()
67.0
Return the distance from the turtle to (x,y), the given vector, or the given
other turtle, in turtle
step units.
>>> turtle.home()
>>> turtle.distance(30,40)
50.0
>>> turtle.distance((30,40))
50.0
>>> turtle.distance(joe)
77.0
turtle. degrees(fullcircle=360.0)
Set angle measurement units, i.e. set number of “degrees” for a full circle.
Default value is
360 degrees.
>>> turtle.home()
>>> turtle.left(90)
>>> turtle.heading()
90.0
>>> turtle.degrees(400.0)
>>> turtle.heading()
100.0
>>> turtle.degrees(360)
>>> turtle.heading()
90.0
turtle. radians()
Set the angle measurement units to radians. Equivalent to
degrees(2*math.pi) .
>>> turtle.home()
>>> turtle.left(90)
>>> turtle.heading()
90.0
>>> turtle.radians()
>>> turtle.heading()
1.5707963267948966
Pen control
Drawing state
turtle. pendown()
turtle. pd()
turtle. down()
Pull the pen down – drawing when moving.
turtle. penup()
turtle. pu()
turtle. up()
Pull the pen up – no drawing when moving.
turtle. pensize(width=None)
turtle. width(width=None)
>>> turtle.pensize()
Parameters: pen – a dictionary with some or all of the below listed keys
pendict – one or more keyword-arguments with the below listed keys as
keywords
“shown”: True/False
“pendown”: True/False
“pencolor”: color-string or color-tuple
“fillcolor”: color-string or color-tuple
“pensize”: positive number
“speed”: number in range 0..10
“resizemode”: “auto” or “user” or “noresize”
“stretchfactor”: (positive number, positive number)
“outline”: positive number
“tilt”: number
>>> sorted(turtle.pen().items())
>>> penstate=turtle.pen()
>>> turtle.penup()
>>> sorted(turtle.pen().items())[:3]
>>> sorted(turtle.pen().items())[:3]
turtle. isdown()
Return True if pen is down, False if it’s up.
>>> turtle.penup()
>>> turtle.isdown()
False
>>> turtle.pendown()
>>> turtle.isdown()
True
Color control
turtle. pencolor(*args)
Return or set the pencolor.
pencolor()
Return the current pencolor as color specification string or
as a tuple (see example). May
be used as input to another
color/pencolor/fillcolor call.
pencolor(colorstring)
Set pencolor to colorstring, which is a Tk color specification string,
such as "red" ,
"yellow" , or "#33cc8c" .
pencolor((r, g, b))
Set pencolor to the RGB color represented by the tuple of r, g, and
b. Each of r, g, and b
must be in the range 0..colormode, where
colormode is either 1.0 or 255 (see
colormode() ).
pencolor(r, g, b)
Set pencolor to the RGB color represented by r, g, and b. Each of
r, g, and b must be in the
range 0..colormode.
>>> colormode()
1.0
>>> turtle.pencolor()
'red'
>>> turtle.pencolor("brown")
>>> turtle.pencolor()
'brown'
>>> turtle.pencolor(tup)
>>> turtle.pencolor()
(0.2, 0.8, 0.5490196078431373)
>>> colormode(255)
>>> turtle.pencolor()
(51.0, 204.0, 140.0)
>>> turtle.pencolor('#32c18f')
>>> turtle.pencolor()
(50.0, 193.0, 143.0)
turtle. fillcolor(*args)
Return or set the fillcolor.
fillcolor()
Return the current fillcolor as color specification string, possibly
in tuple format (see
example). May be used as input to another
color/pencolor/fillcolor call.
fillcolor(colorstring)
Set fillcolor to colorstring, which is a Tk color specification string,
such as "red" , "yellow" ,
or "#33cc8c" .
fillcolor((r, g, b))
Set fillcolor to the RGB color represented by the tuple of r, g, and
b. Each of r, g, and b
must be in the range 0..colormode, where
colormode is either 1.0 or 255 (see
colormode() ).
fillcolor(r, g, b)
Set fillcolor to the RGB color represented by r, g, and b. Each of
r, g, and b must be in the
range 0..colormode.
>>> turtle.fillcolor("violet")
>>> turtle.fillcolor()
'violet'
>>> turtle.pencolor()
(50.0, 193.0, 143.0)
>>> turtle.fillcolor()
>>> turtle.fillcolor('#ffffff')
>>> turtle.fillcolor()
turtle. color(*args)
Return or set pencolor and fillcolor.
color()
Return the current pencolor and the current fillcolor as a pair of color
specification
strings or tuples as returned by pencolor() and
fillcolor() .
>>> turtle.color()
('red', 'green')
>>> color()
Filling
turtle. filling()
Return fillstate ( True if filling, False else).
>>> turtle.begin_fill()
>>> if turtle.filling():
... turtle.pensize(5)
... else:
... turtle.pensize(3)
turtle. begin_fill()
To be called just before drawing a shape to be filled.
turtle. end_fill()
Fill the shape drawn after the last call to begin_fill() .
>>> turtle.begin_fill()
>>> turtle.circle(80)
>>> turtle.end_fill()
turtle. reset()
Delete the turtle’s drawings from the screen, re-center the turtle and set
variables to the
default values.
>>> turtle.goto(0,-22)
>>> turtle.left(100)
>>> turtle.position()
(0.00,-22.00)
>>> turtle.heading()
100.0
>>> turtle.reset()
>>> turtle.position()
(0.00,0.00)
>>> turtle.heading()
0.0
turtle. clear()
Delete the turtle’s drawings from the screen. Do not move turtle. State and
position of the
turtle as well as drawings of other turtles are not affected.
Turtle state
Visibility
turtle. hideturtle()
turtle. ht()
Make the turtle invisible. It’s a good idea to do this while you’re in the
middle of doing some
complex drawing, because hiding the turtle speeds up the
drawing observably.
>>> turtle.hideturtle()
turtle. showturtle()
turtle. st()
Make the turtle visible.
>>> turtle.showturtle()
turtle. isvisible()
Return True if the Turtle is shown, False if it’s hidden.
>>> turtle.hideturtle()
>>>
>>> turtle.isvisible()
False
>>> turtle.showturtle()
>>> turtle.isvisible()
True
Appearance
turtle. shape(name=None)
Set turtle shape to shape with given name or, if name is not given, return
name of current
shape. Shape with name must exist in the TurtleScreen’s
shape dictionary. Initially there are
the following polygon shapes: “arrow”,
“turtle”, “circle”, “square”, “triangle”, “classic”. To learn
about how to
deal with shapes see Screen method register_shape() .
>>> turtle.shape()
'classic'
>>> turtle.shape("turtle")
>>> turtle.shape()
'turtle'
turtle. resizemode(rmode=None)
>>> turtle.resizemode()
'noresize'
>>> turtle.resizemode("auto")
>>> turtle.resizemode()
'auto'
>>> turtle.shapesize()
(1.0, 1.0, 1)
>>> turtle.resizemode("user")
>>> turtle.shapesize()
(5, 5, 12)
>>> turtle.shapesize(outline=8)
>>> turtle.shapesize()
(5, 5, 8)
turtle. shearfactor(shear=None)
>>> turtle.shape("circle")
>>> turtle.shapesize(5,2)
>>> turtle.shearfactor(0.5)
>>> turtle.shearfactor()
0.5
turtle. tilt(angle)
Rotate the turtleshape by angle from its current tilt-angle, but do not
change the turtle’s
heading (direction of movement).
>>> turtle.reset()
>>> turtle.shape("circle")
>>> turtle.shapesize(5,2)
>>> turtle.tilt(30)
>>> turtle.fd(50)
>>> turtle.tilt(30)
>>> turtle.fd(50)
turtle. settiltangle(angle)
>>> turtle.reset()
>>> turtle.shape("circle")
>>> turtle.shapesize(5,2)
>>> turtle.settiltangle(45)
>>> turtle.fd(50)
>>> turtle.settiltangle(-45)
>>> turtle.fd(50)
turtle. tiltangle(angle=None)
>>> turtle.reset()
>>> turtle.shape("circle")
>>> turtle.shapesize(5,2)
>>> turtle.tilt(45)
>>> turtle.tiltangle()
45.0
>>> turtle.shape("square")
>>> turtle.shapesize(4,2)
>>> turtle.shearfactor(-0.5)
>>> turtle.shapetransform()
turtle. get_shapepoly()
Return the current shape polygon as tuple of coordinate pairs. This
can be used to define a
new shape or components of a compound shape.
>>> turtle.shape("square")
>>> turtle.get_shapepoly()
Using events
Parameters: fun – a function with two arguments which will be called with the
coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 (left mouse button)
add – True or False – if True , a new binding will be
added, otherwise it will
replace a former binding
... left(180)
...
>>> onclick(turn) # Now clicking into the turtle will turn it.
Parameters: fun – a function with two arguments which will be called with the
coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 (left mouse button)
add – True or False – if True , a new binding will be
added, otherwise it will
replace a former binding
... self.fillcolor("red")
... self.fillcolor("")
...
Parameters: fun – a function with two arguments which will be called with the
coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 (left mouse button)
add – True or False – if True , a new binding will be
added, otherwise it will
replace a former binding
>>> turtle.ondrag(turtle.goto)
turtle. end_poly()
Stop recording the vertices of a polygon. Current turtle position is last
vertex of polygon. This
will be connected with the first vertex.
turtle. get_poly()
Return the last recorded polygon.
>>> turtle.home()
>>> turtle.begin_poly()
>>> turtle.fd(100)
>>> turtle.left(20)
>>> turtle.fd(30)
>>> turtle.left(60)
>>> turtle.fd(50)
>>> turtle.end_poly()
>>> p = turtle.get_poly()
>>> register_shape("myFavouriteShape", p)
turtle. clone()
Create and return a clone of the turtle with same position, heading and
turtle properties.
turtle. getturtle()
turtle. getpen()
Return the Turtle object itself. Only reasonable use: as a function to
return the “anonymous
turtle”:
>>> pet.fd(50)
>>> pet
turtle. getscreen()
Return the TurtleScreen object the turtle is drawing on.
TurtleScreen methods can then be
called for that object.
>>> ts = turtle.getscreen()
>>> ts
>>> ts.bgcolor("pink")
turtle. setundobuffer(size)
>>> turtle.setundobuffer(42)
turtle. undobufferentries()
Return number of entries in the undobuffer.
... undo()
Compound shapes
To use compound turtle shapes, which consist of several polygons of different
color, you must
use the helper class Shape explicitly as described
below:
For example:
>>> s = Shape("compound")
3. Now add the Shape to the Screen’s shapelist and use it:
>>> register_shape("myshape", s)
>>> shape("myshape")
Note:
The Shape class is used internally by the register_shape()
method in different ways. The
application programmer has to deal with the
Shape class only when using compound shapes
like shown above!
turtle. bgcolor(*args)
>>> screen.bgcolor("orange")
>>> screen.bgcolor()
'orange'
>>> screen.bgcolor("#800080")
>>> screen.bgcolor()
turtle. bgpic(picname=None)
>>> screen.bgpic()
>>>
'nopic'
>>> screen.bgpic("landscape.gif")
>>> screen.bgpic()
"landscape.gif"
turtle. clear()
Note:
This TurtleScreen method is available as a global function only under the
name
clearscreen . The global function clear is a different one
derived from the Turtle method
clear .
turtle. clearscreen()
Delete all drawings and all turtles from the TurtleScreen. Reset the now
empty TurtleScreen
to its initial state: white background, no background
image, no event bindings and tracing on.
turtle. reset()
Note:
This TurtleScreen method is available as a global function only under the
name
resetscreen . The global function reset is another one
derived from the Turtle method reset .
turtle. resetscreen()
Reset all Turtles on the Screen to their initial state.
>>> screen.screensize()
>>>
(400, 300)
>>> screen.screensize(2000,1500)
>>> screen.screensize()
(2000, 1500)
>>> screen.reset()
>>> screen.setworldcoordinates(-50,-7.5,50,7.5)
... left(10)
...
Animation control
turtle. delay(delay=None)
Optional argument:
>>> screen.delay()
10
>>> screen.delay(5)
>>> screen.delay()
Turn turtle animation on/off and set delay for update drawings. If
n is given, only each n-th
regular screen update is really
performed. (Can be used to accelerate the drawing of
complex
graphics.) When called without arguments, returns the currently
stored value of n.
Second argument sets delay value (see
delay() ).
>>> dist = 2
... fd(dist)
... rt(90)
... dist += 2
turtle. update()
Perform a TurtleScreen update. To be used when tracer is turned off.
... fd(50)
... lt(60)
...
>>> screen.listen()
... fd(50)
...
>>> screen.listen()
Parameters: fun – a function with two arguments which will be called with the
coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 (left mouse button)
add – True or False – if True , a new binding will be
added, otherwise it will
replace a former binding
Note:
This TurtleScreen method is available as a global function only under the
name
onscreenclick . The global function onclick is another one
derived from the Turtle method
onclick .
turtle. ontimer(fun, t=0)
... if running:
... fd(50)
... lt(60)
turtle. mainloop()
turtle. done()
Starts event loop - calling Tkinter’s mainloop function.
Must be the last statement in a turtle
graphics program.
Must not be used if a script is run from within IDLE in -n mode
(No
subprocess) - for interactive use of turtle graphics.
>>> screen.mainloop()
>>>
Input methods
turtle. mode(mode=None)
Set turtle mode (“standard”, “logo” or “world”) and perform reset. If mode
is not given, current
mode is returned.
>>> mode()
'logo'
turtle. colormode(cmode=None)
>>> screen.colormode(1)
...
>>> screen.colormode()
1.0
>>> screen.colormode(255)
>>> screen.colormode()
255
>>> turtle.pencolor(240,160,80)
turtle. getcanvas()
Return the Canvas of this TurtleScreen. Useful for insiders who know what to
do with a
Tkinter Canvas.
>>> cv = screen.getcanvas()
>>> cv
turtle. getshapes()
Return a list of names of all currently available turtle shapes.
>>> screen.getshapes()
>>> screen.register_shape("turtle.gif")
>>>
Note:
Image shapes do not rotate when turning the turtle, so they do not
display the
heading of the turtle!
turtle. turtles()
Return the list of turtles on the screen.
... turtle.color("red")
turtle. window_height()
Return the height of the turtle window.
>>> screen.window_height()
>>>
480
turtle. window_width()
Return the width of the turtle window.
>>> screen.window_width()
>>>
640
turtle. bye()
Shut the turtlegraphics window.
turtle. exitonclick()
Bind bye() method to mouse clicks on the Screen.
turtle. title(titlestring)
Parameters: titlestring – a string that is shown in the titlebar of the turtle
graphics window
Public classes
class turtle. RawTurtle(canvas)
class turtle. RawPen(canvas)
Create a turtle. The turtle has all methods described above as “methods of
Turtle/RawTurtle”.
Parameters: cv – a tkinter.Canvas
Provides screen oriented methods like setbg() etc. that are described
above.
Data structure modeling shapes. The pair (type_, data) must follow this
specification:
type_ data
“polygon” a polygon-tuple, i.e. a tuple of pairs of coordinates
“image” an image (in this form only used internally!)
type_ data
None (a compound shape has to be constructed using the
addcomponent()
“compound”
method)
Example:
>>> s = Shape("compound")
a + b vector addition
a - b vector subtraction
a * b inner product
k * a and a * k multiplication with scalar
abs(a) absolute value of a
a.rotate(angle) rotation
The public methods of the Screen and Turtle classes are documented extensively
via docstrings.
So these can be used as online-help via the Python help
facilities:
When using IDLE, tooltips show the signatures and first lines of the
docstrings of typed in
function-/method calls.
Calling help() on methods or functions displays the docstrings:
>>> help(Screen.bgcolor)
>>>
Help on method bgcolor in module turtle:
>>> screen.bgcolor("orange")
>>> screen.bgcolor()
"orange"
>>> screen.bgcolor(0.5,0,0.5)
>>> screen.bgcolor()
"#800080"
>>> help(Turtle.penup)
Aliases: penup | pu | up
No argument
>>> turtle.penup()
The docstrings of the functions which are derived from methods have a modified
form:
>>> help(bgcolor)
>>>
Help on function bgcolor in module turtle:
bgcolor(*args)
Example::
>>> bgcolor("orange")
>>> bgcolor()
"orange"
>>> bgcolor(0.5,0,0.5)
>>> bgcolor()
"#800080"
>>> help(penup)
penup()
Aliases: penup | pu | up
No argument
Example:
>>> penup()
These modified docstrings are created automatically together with the function
definitions that
are derived from the methods at import time.
turtle. write_docstringdict(filename="turtle_docstringdict")
If you (or your students) want to use turtle with online help in your
native language, you have to
translate the docstrings and save the resulting
file as e.g. turtle_docstringdict_german.py .
At the time of this writing there are docstring dictionaries in German and in
Italian. (Requests
please to [email protected].)
The built-in default configuration mimics the appearance and behaviour of the
old turtle module
in order to retain best possible compatibility with it.
If you want to use a different configuration which better reflects the features
of this module or
which better fits to your needs, e.g. for use in a classroom,
you can prepare a configuration file
turtle.cfg which will be read at import
time and modify the configuration according to its settings.
width = 0.5
height = 0.75
leftright = None
topbottom = None
canvwidth = 400
canvheight = 300
mode = standard
colormode = 1.0
delay = 10
undobuffersize = 1000
shape = classic
pencolor = black
fillcolor = black
resizemode = noresize
visible = True
language = english
exampleturtle = turtle
examplescreen = screen
using_IDLE = False
python -m turtledemo
Alternatively, you can run the demo scripts individually. For example,
python -m turtledemo.bytedesign
turtle: appearance
and
peace elementary
animation
penrose aperiodic tiling with
kites and darts stamp()
planet_and_moon simulation of
gravitational system compound shapes,
Vec2D
compound shapes, clone
dancing turtles rotating
pairwise in
round_dance shapesize, tilt,
get_shapepoly,
opposite
direction
update
Name Description Features
visual demonstration of
different simple alignment,
sorting_animate
sorting methods randomization
a (graphical) breadth
first tree (using
tree clone()
generators)
two_canvases simple design turtles on two
canvases
a pattern from the wikipedia
article on
wikipedia clone() ,
undo()
turtle graphics
yinyang another elementary example circle()
Have fun!