8000 [3.12] gh-106996: Rewrite turtle explanation (GH-107244) (#107335) · python/cpython@38c982d · GitHub
[go: up one dir, main page]

Skip to content

Commit 38c982d

Browse files
miss-islingtonevildmphugovk
authored
[3.12] gh-106996: Rewrite turtle explanation (GH-107244) (#107335)
Co-authored-by: Daniele Procida <daniele@vurt.org> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
1 parent 5f3e371 commit 38c982d

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

@@ -2465,6 +2414,41 @@ Public classes
24652414
* ``a.rotate(angle)`` rotation
24662415

24672416

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

0 commit comments

Comments
 (0)
0