Skip to content

Commit 8f0dc18

Browse files
miss-islingtonevildmphugovk
authored
[3.11] gh-106996: Rewrite turtle explanation (GH-107244) (#107336)
Co-authored-by: Daniele Procida <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 9513acf commit 8f0dc18

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
@@ -277,67 +277,16 @@ The turtle's screen can be customised, for example::
277277
t.screen.bgcolor("orange")
278278

279279

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

332283
.. note::
284+
333285
In the following documentation the argument list for functions is given.
334286
Methods, of course, have the additional first argument *self* which is
335287
omitted here.
336288

337289

338-
Turtle graphics reference
339-
=========================
340-
341290
Turtle methods
342291
--------------
343292

@@ -2434,6 +2383,41 @@ Public classes
24342383
* ``a.rotate(angle)`` rotation
24352384

24362385

2386+
.. _turtle-explanation:
2387+
2388+
Explanation
2389+
===========
2390+
2391+
A turtle object draws on a screen object, and there a number of key classes in
2392+
the turtle object-oriented interface that can be used to create them and relate
2393+
them to each other.
2394+
2395+
A :class:`Turtle` instance will automatically create a :class:`Screen`
2396+
instance if one is not already present.
2397+
2398+
``Turtle`` is a subclass of :class:`RawTurtle`, which *doesn't* automatically
2399+
create a drawing surface - a *canvas* will need to be provided or created for
2400+
it. The *canvas* can be a :class:`tkinter.Canvas`, :class:`ScrolledCanvas`
2401+
or :class:`TurtleScreen`.
2402+
2403+
2404+
:class:`TurtleScreen` is the basic drawing surface for a
2405+
turtle. :class:`Screen` is a subclass of ``TurtleScreen``, and
2406+
includes :ref:`some additional methods <screenspecific>` for managing its
2407+
appearance (including size and title) and behaviour. ``TurtleScreen``'s
2408+
constructor needs a :class:`tkinter.Canvas` or a
2409+
:class:`ScrolledCanvas` as an argument.
2410+
2411+
The functional interface for turtle graphics uses the various methods of
2412+
``Turtle`` and ``TurtleScreen``/``Screen``. Behind the scenes, a screen
2413+
object is automatically created whenever a function derived from a ``Screen``
2414+
method is called. Similarly, a turtle object is automatically created
2415+
whenever any of the functions derived from a Turtle method is called.
2416+
2417+
To use multiple turtles on a screen, the object-oriented interface must be
2418+
used.
2419+
2420+
24372421
Help and configuration
24382422
======================
24392423

0 commit comments

Comments
 (0)