Skip to content

Commit 821ebc7

Browse files
[3.14] gh-157847: Rewrite turtle module docs introduction (GH-157854) (#158096)
(cherry picked from commit 9b3fc89)
1 parent 455c554 commit 821ebc7

2 files changed

Lines changed: 41 additions & 58 deletions

File tree

‎Doc/includes/optional-module.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ If you are the distributor, see :ref:`optional-module-requirements`.
77
.. Similar notes appear in the docs of the modules:
88
- zipfile
99
- tarfile
10+
- turtle

‎Doc/library/turtle.rst‎

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@
2323

2424
--------------
2525

26-
Introduction
27-
============
28-
29-
Turtle graphics is an implementation of `the popular geometric drawing tools
30-
introduced in Logo <https://en.wikipedia.org/wiki/Turtle_
31-
(robot)>`_, developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon
32-
in 1967.
33-
34-
.. include:: ../includes/optional-module.rst
35-
36-
37-
Get started
38-
===========
39-
40-
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it the
41-
command ``turtle.forward(15)``, and it moves (on-screen!) 15 pixels in the
42-
direction it is facing, drawing a line as it moves. Give it the command
43-
``turtle.right(25)``, and it rotates in-place 25 degrees clockwise.
44-
4526
.. sidebar:: Turtle star
4627

4728
Turtle can draw intricate shapes using programs that repeat simple
@@ -50,21 +31,40 @@ direction it is facing, drawing a line as it moves. Give it the command
5031
.. image:: turtle-star.png
5132
:align: center
5233

53-
In Python, turtle graphics provides a representation of a physical "turtle"
54-
(a little robot with a pen) that draws on a sheet of paper on the floor.
34+
Imagine a robotic turtle starting at (0, 0) in the x-y plane.
35+
After an ``import turtle``, give it the command ``turtle.forward(15)``, and it
36+
moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as
37+
it moves. Give it the command ``turtle.right(25)``, and it rotates in-place 25
38+
degrees clockwise.
39+
40+
Turtle graphics is an implementation of `the drawing tools introduced in Logo
41+
<https://en.wikipedia.org/wiki/Turtle_(robot)>`_ in 1967. It was created as an
42+
educational tool, and its instant, visible feedback makes it an effective way
43+
for learners to encounter programming concepts. It is also a convenient way to
44+
produce simple graphical output without bringing in external libraries.
45+
46+
This document includes four main sections:
5547

56-
It's an effective and well-proven way for learners to encounter
57-
programming concepts and interaction with software, as it provides instant,
58-
visible feedback. It also provides convenient access to graphical output
59-
in general.
48+
* :ref:`turtle-tutorial` teaches the basics of turtle drawing.
49+
* :ref:`turtle-reference` describes the functions, methods and classes this
50+
module defines.
51+
* :ref:`turtle-howtos` details how to handle specific tasks.
52+
* :ref:`turtle-explanation` provides background on the object-oriented
53+
interface.
54+
55+
.. note::
6056

61-
Turtle drawing was originally created as an educational tool, to be used by
62-
teachers in the classroom. For the programmer who needs to produce some
63-
graphical output it can be a way to do that without the overhead of
64-
introducing more complex or external libraries into their work.
57+
Turtle graphics requires the :mod:`tkinter` :term:`optional module`.
58+
The python.org installers for Windows and macOS include it, but some
59+
Linux distributions and other platforms may package it separately. If
60+
``import turtle`` fails with an error mentioning ``_tkinter``, look for
61+
documentation from your distributor (that is, whoever provided Python to you).
62+
Check this in advance if you're planning to use turtle graphics with a learner.
6563

6664

6765
.. _turtle-tutorial:
66+
.. _get-started:
67+
.. _get-started-as-quickly-as-possible:
6868

6969
Tutorial
7070
========
@@ -107,7 +107,8 @@ Notice how the turtle, represented by an arrow, points in different
107107
directions as you steer it.
108108

109109
Experiment with those commands, and also with ``backward()`` and
110-
``right()``.
110+
``right()``. Many commands also have terser aliases, such as ``fd()`` for
111+
:func:`forward`.
111112

112113

113114
Pen control
@@ -187,38 +188,16 @@ Finally, complete the filling::
187188
``end_fill()`` command.)
188189

189190

191+
.. _turtle-howtos:
190192
.. _turtle-how-to:
193+
.. _how-to:
191194

192-
How to...
193-
=========
195+
How-to guides
196+
=============
194197

195198
This section covers some typical turtle use-cases and approaches.
196199

197200

198-
Get started as quickly as possible
199-
----------------------------------
200-
201-
One of the joys of turtle graphics is the immediate, visual feedback that's
202-
available from simple commands - it's an excellent way to introduce children
203-
to programming ideas, with a minimum of overhead (not just children, of
204-
course).
205-
206-
The turtle module makes this possible by exposing all its basic functionality
207-
as functions, available with ``from turtle import *``. The :ref:`turtle
208-
graphics tutorial <turtle-tutorial>` covers this approach.
209-
210-
It's worth noting that many of the turtle commands also have even more terse
211-
equivalents, such as ``fd()`` for :func:`forward`. These are especially
212-
useful when working with learners for whom typing is not a skill.
213-
214-
.. _note:
215-
216-
You'll need to have the :mod:`Tk interface package <tkinter>` installed on
217-
your system for turtle graphics to work. Be warned that this is not
218-
always straightforward, so check this in advance if you're planning to
219-
use turtle graphics with a learner.
220-
221-
222201
Automatically begin and end filling
223202
-----------------------------------
224203

@@ -322,8 +301,11 @@ The turtle's screen can be customised, for example::
322301
t.screen.bgcolor("orange")
323302

324303

325-
Turtle graphics reference
326-
=========================
304+
.. _turtle-reference:
305+
.. _turtle-graphics-reference:
306+
307+
Reference
308+
=========
327309

328310
.. note::
329311

0 commit comments

Comments
 (0)