Skip to content

Commit ccd4253

Browse files
evildmphugovk
andauthored
gh-106996: Rewrite turtle explanation (#107244)
Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 71b3eda commit ccd4253

File tree

1 file changed

+38
-54
lines changed

1 file changed

+38
-54
lines changed

Doc/library/turtle.rst

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -286,67 +286,16 @@ The turtle's screen can be customised, for example::
286286
t.screen.bgcolor("orange")
287287

288288

289-
.. _turtle-explanation:
290-
291-
Explanation
292-
===========
293-
294-
The :mod:`turtle` module is an extended reimplementation of the same-named
295-
module from the Python standard distribution up to version Python 2.5.
296-
297-
It tries to keep the merits of the old turtle module and to be (nearly) 100%
298-
compatible with it. This means in the first place to enable the learning
299-
programmer to use all the commands, classes and methods interactively when using
300-
the module from within IDLE run with the ``-n`` switch.
301-
302-
The turtle module provides turtle graphics primitives, in both object-oriented
303-
and procedure-oriented ways. Because it uses :mod:`tkinter` for the underlying
304-
graphics, it needs a version of Python installed with Tk support.
305-
306-
The object-oriented interface uses essentially two+two classes:
307-
308-
1. The :class:`TurtleScreen` class defines graphics windows as a playground for
309-
the drawing turtles. Its constructor needs a :class:`tkinter.Canvas` or a
310-
:class:`ScrolledCanvas` as argument. It should be used when :mod:`turtle` is
311-
used as part of some application.
312-
313-
The function :func:`Screen` returns a singleton object of a
314-
:class:`TurtleScreen` subclass. This function should be used when
315-
:mod:`turtle` is used as a standalone tool for doing graphics.
316-
As a singleton object, inheriting from its class is not possible.
317-
318-
All methods of TurtleScreen/Screen also exist as functions, i.e. as part of
319-
the procedure-oriented interface.
320-
321-
2. :class:`RawTurtle` (alias: :class:`RawPen`) defines Turtle objects which draw
322-
on a :class:`TurtleScreen`. Its constructor needs a Canvas, ScrolledCanvas
323-
or TurtleScreen as argument, so the RawTurtle objects know where to draw.
324-
325-
Derived from RawTurtle is the subclass :class:`Turtle` (alias: :class:`Pen`),
326-
which draws on "the" :class:`Screen` instance which is automatically
327-
created, if not already present.
328-
329-
All methods of RawTurtle/Turtle also exist as functions, i.e. part of the
330-
procedure-oriented interface.
331-
332-
The procedural interface provides functions which are derived from the methods
333-
of the classes :class:`Screen` and :class:`Turtle`. They have the same names as
334-
the corresponding methods. A screen object is automatically created whenever a
335-
function derived from a Screen method is called. An (unnamed) turtle object is
336-
automatically created whenever any of the functions derived from a Turtle method
337-
is called.
338-
339-
To use multiple turtles on a screen one has to use the object-oriented interface.
289+
Turtle graphics reference
290+
=========================
340291

341292
.. note::
293+
342294
In the following documentation the argument list for functions is given.
343295
Methods, of course, have the additional first argument *self* which is
344296
omitted here.
345297

346298

347-
Turtle graphics reference
348-
=========================
349-
350299
Turtle methods
351300
--------------
352301

@@ -2451,6 +2400,41 @@ Public classes
24512400
* ``a.rotate(angle)`` rotation
24522401

24532402

2403+
.. _turtle-explanation:
2404+
2405+
Explanation
2406+
===========
2407+
2408+
A turtle object draws on a screen object, and there a number of key classes in
2409+
the turtle object-oriented interface that can be used to create them and relate
2410+
them to each other.
2411+
2412+
A :class:`Turtle` instance will automatically create a :class:`Screen`
2413+
instance if one is not already present.
2414+
2415+
``Turtle`` is a subclass of :class:`RawTurtle`, which *doesn't* automatically
2416+
create a drawing surface - a *canvas* will need to be provided or created for
2417+
it. The *canvas* can be a :class:`tkinter.Canvas`, :class:`ScrolledCanvas`
2418+
or :class:`TurtleScreen`.
2419+
2420+
2421+
:class:`TurtleScreen` is the basic drawing surface for a
2422+
turtle. :class:`Screen` is a subclass of ``TurtleScreen``, and
2423+
includes :ref:`some additional methods <screenspecific>` for managing its
2424+
appearance (including size and title) and behaviour. ``TurtleScreen``'s
2425+
constructor needs a :class:`tkinter.Canvas` or a
2426+
:class:`ScrolledCanvas` as an argument.
2427+
2428+
The functional interface for turtle graphics uses the various methods of
2429+
``Turtle`` and ``TurtleScreen``/``Screen``. Behind the scenes, a screen
2430+
object is automatically created whenever a function derived from a ``Screen``
2431+
method is called. Similarly, a turtle object is automatically created
2432+
whenever any of the functions derived from a Turtle method is called.
2433+
2434+
To use multiple turtles on a screen, the object-oriented interface must be
2435+
used.
2436+
2437+
24542438
Help and configuration
24552439
======================
24562440

0 commit comments

Comments
 (0)