Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:16.3 ScrolledTextUp:16. Graphical User InterfacesNext:16.4.1 Pen and RawPen

16.4turtle -- Turtle graphics for Tk

Availability:Tk.

Theturtle module provides turtle graphics primitives, in both anobject-oriented and procedure-oriented ways. Because it usesTkinterfor the underlying graphics, it needs a version of python installed withTk support.

The procedural interface uses a pen and a canvas which are automagicallycreated when any of the functions are called.

Theturtle module defines the following functions:

degrees()
Set angle measurement units to degrees.

radians()
Set angle measurement units to radians.

reset()
Clear the screen, re-center the pen, and set variables to the defaultvalues.

clear()
Clear the screen.

tracer(flag)
Set tracing on/off (according to whether flag is true or not). Tracingmeans line are drawn more slowly, with an animation of an arrow along the line.

forward(distance)
Go forwarddistance steps.

backward(distance)
Go backwarddistance steps.

left(angle)
Turn leftangle units. Units are by default degrees, but can beset via thedegrees() andradians() functions.

right(angle)
Turn rightangle units. Units are by default degrees, but can beset via thedegrees() andradians() functions.

up()
Move the pen up -- stop drawing.

down()
Move the pen up -- draw when moving.

width(width)
Set the line width towidth.

color(s)
color((r, g, b))
color(r, g, b)
Set the pen color. In the first form, the color is specified as aTk color specification as a string. The second form specifies thecolor as a tuple of the RGB values, each in the range [0..1]. For thethird form, the color is specified giving the RGB values as threeseparate parameters (each in the range [0..1]).

write(text[, move])
Writetext at the current pen position. Ifmove is true,the pen is moved to the bottom-right corner of the text. By default,move is false.

fill(flag)
The complete specifications are rather complex, but the recommended usage is: callfill(1) before drawing a path you want to fill,and callfill(0) when you finish to draw the path.

circle(radius[, extent])
Draw a circle with radiusradius whose center-point isradius units left of the turtle.extent determines which part of a circle is drawn: ifnot given it defaults to a full circle.

Ifextent is not a full circle, one endpoint of the arc is thecurrent pen position. The arc is drawn in a counter clockwisedirection ifradius is positive, otherwise in a clockwisedirection. In the process, the direction of the turtle is changedby the amount of theextent.

goto(x, y)
goto((x, y))
Go to co-ordinatesx,y. The co-ordinates may bespecified either as two separate arguments or as a 2-tuple.

This module also doesfrom math import *, so see thedocumentation for themath module for additional constantsand functions useful for turtle graphics.

demo()
Exercise the module a bit.

exceptionError
Exception raised on any error caught by this module.

For examples, see the code of thedemo() function.

This module defines the following classes:

classPen()
Define a pen. All above functions can be called as a methods on the givenpen. The constructor automatically creates a canvas do be drawn on.

classRawPen(canvas)
Define a pen which draws on a canvascanvas. This is useful if you want to use the module to create graphics in a ``real'' program.


Subsections


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:16.3 ScrolledTextUp:16. Graphical User InterfacesNext:16.4.1 Pen and RawPen
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp