2925 lines
237 KiB
HTML
2925 lines
237 KiB
HTML
|
|
|||
|
<!DOCTYPE html>
|
|||
|
|
|||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|||
|
<head>
|
|||
|
<meta charset="utf-8" />
|
|||
|
<title>turtle — Turtle graphics — Python 3.7.4 documentation</title>
|
|||
|
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
|||
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|||
|
|
|||
|
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/language_data.js"></script>
|
|||
|
|
|||
|
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
|||
|
|
|||
|
<link rel="search" type="application/opensearchdescription+xml"
|
|||
|
title="Search within Python 3.7.4 documentation"
|
|||
|
href="../_static/opensearch.xml"/>
|
|||
|
<link rel="author" title="About these documents" href="../about.html" />
|
|||
|
<link rel="index" title="Index" href="../genindex.html" />
|
|||
|
<link rel="search" title="Search" href="../search.html" />
|
|||
|
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
|||
|
<link rel="next" title="cmd — Support for line-oriented command interpreters" href="cmd.html" />
|
|||
|
<link rel="prev" title="Program Frameworks" href="frameworks.html" />
|
|||
|
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
|||
|
<link rel="canonical" href="https://docs.python.org/3/library/turtle.html" />
|
|||
|
|
|||
|
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/switchers.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<style>
|
|||
|
@media only screen {
|
|||
|
table.full-width-table {
|
|||
|
width: 100%;
|
|||
|
}
|
|||
|
}
|
|||
|
</style>
|
|||
|
|
|||
|
|
|||
|
</head><body>
|
|||
|
|
|||
|
<div class="related" role="navigation" aria-label="related navigation">
|
|||
|
<h3>Navigation</h3>
|
|||
|
<ul>
|
|||
|
<li class="right" style="margin-right: 10px">
|
|||
|
<a href="../genindex.html" title="General Index"
|
|||
|
accesskey="I">index</a></li>
|
|||
|
<li class="right" >
|
|||
|
<a href="../py-modindex.html" title="Python Module Index"
|
|||
|
>modules</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="cmd.html" title="cmd — Support for line-oriented command interpreters"
|
|||
|
accesskey="N">next</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="frameworks.html" title="Program Frameworks"
|
|||
|
accesskey="P">previous</a> |</li>
|
|||
|
<li><img src="../_static/py.png" alt=""
|
|||
|
style="vertical-align: middle; margin-top: -1px"/></li>
|
|||
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|||
|
<li>
|
|||
|
<span class="language_switcher_placeholder">en</span>
|
|||
|
<span class="version_switcher_placeholder">3.7.4</span>
|
|||
|
<a href="../index.html">Documentation </a> »
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
|||
|
<li class="nav-item nav-item-2"><a href="frameworks.html" accesskey="U">Program Frameworks</a> »</li>
|
|||
|
<li class="right">
|
|||
|
|
|||
|
|
|||
|
<div class="inline-search" style="display: none" role="search">
|
|||
|
<form class="inline-search" action="../search.html" method="get">
|
|||
|
<input placeholder="Quick search" type="text" name="q" />
|
|||
|
<input type="submit" value="Go" />
|
|||
|
<input type="hidden" name="check_keywords" value="yes" />
|
|||
|
<input type="hidden" name="area" value="default" />
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
<script type="text/javascript">$('.inline-search').show(0);</script>
|
|||
|
|
|
|||
|
</li>
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="document">
|
|||
|
<div class="documentwrapper">
|
|||
|
<div class="bodywrapper">
|
|||
|
<div class="body" role="main">
|
|||
|
|
|||
|
<div class="section" id="module-turtle">
|
|||
|
<span id="turtle-turtle-graphics"></span><h1><a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> — Turtle graphics<a class="headerlink" href="#module-turtle" title="Permalink to this headline">¶</a></h1>
|
|||
|
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/turtle.py">Lib/turtle.py</a></p>
|
|||
|
<hr class="docutils" />
|
|||
|
<div class="section" id="introduction">
|
|||
|
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>Turtle graphics is a popular way for introducing programming to kids. It was
|
|||
|
part of the original Logo programming language developed by Wally Feurzeig,
|
|||
|
Seymour Papert and Cynthia Solomon in 1967.</p>
|
|||
|
<p>Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">turtle</span></code>, give it the
|
|||
|
command <code class="docutils literal notranslate"><span class="pre">turtle.forward(15)</span></code>, and it moves (on-screen!) 15 pixels in the
|
|||
|
direction it is facing, drawing a line as it moves. Give it the command
|
|||
|
<code class="docutils literal notranslate"><span class="pre">turtle.right(25)</span></code>, and it rotates in-place 25 degrees clockwise.</p>
|
|||
|
<div class="sidebar">
|
|||
|
<p class="sidebar-title">Turtle star</p>
|
|||
|
<p>Turtle can draw intricate shapes using programs that repeat simple
|
|||
|
moves.</p>
|
|||
|
<img alt="../_images/turtle-star.png" class="align-center" src="../_images/turtle-star.png" />
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">turtle</span> <span class="k">import</span> <span class="o">*</span>
|
|||
|
<span class="n">color</span><span class="p">(</span><span class="s1">'red'</span><span class="p">,</span> <span class="s1">'yellow'</span><span class="p">)</span>
|
|||
|
<span class="n">begin_fill</span><span class="p">()</span>
|
|||
|
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
|
|||
|
<span class="n">forward</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span>
|
|||
|
<span class="n">left</span><span class="p">(</span><span class="mi">170</span><span class="p">)</span>
|
|||
|
<span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">pos</span><span class="p">())</span> <span class="o"><</span> <span class="mi">1</span><span class="p">:</span>
|
|||
|
<span class="k">break</span>
|
|||
|
<span class="n">end_fill</span><span class="p">()</span>
|
|||
|
<span class="n">done</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>By combining together these and similar commands, intricate shapes and pictures
|
|||
|
can easily be drawn.</p>
|
|||
|
<p>The <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> module is an extended reimplementation of the same-named
|
|||
|
module from the Python standard distribution up to version Python 2.5.</p>
|
|||
|
<p>It tries to keep the merits of the old turtle module and to be (nearly) 100%
|
|||
|
compatible with it. This means in the first place to enable the learning
|
|||
|
programmer to use all the commands, classes and methods interactively when using
|
|||
|
the module from within IDLE run with the <code class="docutils literal notranslate"><span class="pre">-n</span></code> switch.</p>
|
|||
|
<p>The turtle module provides turtle graphics primitives, in both object-oriented
|
|||
|
and procedure-oriented ways. Because it uses <a class="reference internal" href="tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> for the underlying
|
|||
|
graphics, it needs a version of Python installed with Tk support.</p>
|
|||
|
<p>The object-oriented interface uses essentially two+two classes:</p>
|
|||
|
<ol class="arabic">
|
|||
|
<li><p>The <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> class defines graphics windows as a playground for
|
|||
|
the drawing turtles. Its constructor needs a <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code> or a
|
|||
|
<a class="reference internal" href="#turtle.ScrolledCanvas" title="turtle.ScrolledCanvas"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScrolledCanvas</span></code></a> as argument. It should be used when <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> is
|
|||
|
used as part of some application.</p>
|
|||
|
<p>The function <a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-func docutils literal notranslate"><span class="pre">Screen()</span></code></a> returns a singleton object of a
|
|||
|
<a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> subclass. This function should be used when
|
|||
|
<a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> is used as a standalone tool for doing graphics.
|
|||
|
As a singleton object, inheriting from its class is not possible.</p>
|
|||
|
<p>All methods of TurtleScreen/Screen also exist as functions, i.e. as part of
|
|||
|
the procedure-oriented interface.</p>
|
|||
|
</li>
|
|||
|
<li><p><a class="reference internal" href="#turtle.RawTurtle" title="turtle.RawTurtle"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawTurtle</span></code></a> (alias: <a class="reference internal" href="#turtle.RawPen" title="turtle.RawPen"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawPen</span></code></a>) defines Turtle objects which draw
|
|||
|
on a <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a>. Its constructor needs a Canvas, ScrolledCanvas
|
|||
|
or TurtleScreen as argument, so the RawTurtle objects know where to draw.</p>
|
|||
|
<p>Derived from RawTurtle is the subclass <a class="reference internal" href="#turtle.Turtle" title="turtle.Turtle"><code class="xref py py-class docutils literal notranslate"><span class="pre">Turtle</span></code></a> (alias: <code class="xref py py-class docutils literal notranslate"><span class="pre">Pen</span></code>),
|
|||
|
which draws on “the” <a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code></a> instance which is automatically
|
|||
|
created, if not already present.</p>
|
|||
|
<p>All methods of RawTurtle/Turtle also exist as functions, i.e. part of the
|
|||
|
procedure-oriented interface.</p>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<p>The procedural interface provides functions which are derived from the methods
|
|||
|
of the classes <a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code></a> and <a class="reference internal" href="#turtle.Turtle" title="turtle.Turtle"><code class="xref py py-class docutils literal notranslate"><span class="pre">Turtle</span></code></a>. They have the same names as
|
|||
|
the corresponding methods. A screen object is automatically created whenever a
|
|||
|
function derived from a Screen method is called. An (unnamed) turtle object is
|
|||
|
automatically created whenever any of the functions derived from a Turtle method
|
|||
|
is called.</p>
|
|||
|
<p>To use multiple turtles on a screen one has to use the object-oriented interface.</p>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>In the following documentation the argument list for functions is given.
|
|||
|
Methods, of course, have the additional first argument <em>self</em> which is
|
|||
|
omitted here.</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="overview-of-available-turtle-and-screen-methods">
|
|||
|
<h2>Overview of available Turtle and Screen methods<a class="headerlink" href="#overview-of-available-turtle-and-screen-methods" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="turtle-methods">
|
|||
|
<h3>Turtle methods<a class="headerlink" href="#turtle-methods" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl>
|
|||
|
<dt>Turtle motion</dt><dd><dl>
|
|||
|
<dt>Move and draw</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.forward" title="turtle.forward"><code class="xref py py-func docutils literal notranslate"><span class="pre">forward()</span></code></a> | <a class="reference internal" href="#turtle.fd" title="turtle.fd"><code class="xref py py-func docutils literal notranslate"><span class="pre">fd()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.backward" title="turtle.backward"><code class="xref py py-func docutils literal notranslate"><span class="pre">backward()</span></code></a> | <a class="reference internal" href="#turtle.bk" title="turtle.bk"><code class="xref py py-func docutils literal notranslate"><span class="pre">bk()</span></code></a> | <a class="reference internal" href="#turtle.back" title="turtle.back"><code class="xref py py-func docutils literal notranslate"><span class="pre">back()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.right" title="turtle.right"><code class="xref py py-func docutils literal notranslate"><span class="pre">right()</span></code></a> | <a class="reference internal" href="#turtle.rt" title="turtle.rt"><code class="xref py py-func docutils literal notranslate"><span class="pre">rt()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.left" title="turtle.left"><code class="xref py py-func docutils literal notranslate"><span class="pre">left()</span></code></a> | <a class="reference internal" href="#turtle.lt" title="turtle.lt"><code class="xref py py-func docutils literal notranslate"><span class="pre">lt()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.goto" title="turtle.goto"><code class="xref py py-func docutils literal notranslate"><span class="pre">goto()</span></code></a> | <a class="reference internal" href="#turtle.setpos" title="turtle.setpos"><code class="xref py py-func docutils literal notranslate"><span class="pre">setpos()</span></code></a> | <a class="reference internal" href="#turtle.setposition" title="turtle.setposition"><code class="xref py py-func docutils literal notranslate"><span class="pre">setposition()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.setx" title="turtle.setx"><code class="xref py py-func docutils literal notranslate"><span class="pre">setx()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.sety" title="turtle.sety"><code class="xref py py-func docutils literal notranslate"><span class="pre">sety()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.setheading" title="turtle.setheading"><code class="xref py py-func docutils literal notranslate"><span class="pre">setheading()</span></code></a> | <a class="reference internal" href="#turtle.seth" title="turtle.seth"><code class="xref py py-func docutils literal notranslate"><span class="pre">seth()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.home" title="turtle.home"><code class="xref py py-func docutils literal notranslate"><span class="pre">home()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.circle" title="turtle.circle"><code class="xref py py-func docutils literal notranslate"><span class="pre">circle()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.dot" title="turtle.dot"><code class="xref py py-func docutils literal notranslate"><span class="pre">dot()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.stamp" title="turtle.stamp"><code class="xref py py-func docutils literal notranslate"><span class="pre">stamp()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.clearstamp" title="turtle.clearstamp"><code class="xref py py-func docutils literal notranslate"><span class="pre">clearstamp()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.clearstamps" title="turtle.clearstamps"><code class="xref py py-func docutils literal notranslate"><span class="pre">clearstamps()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.undo" title="turtle.undo"><code class="xref py py-func docutils literal notranslate"><span class="pre">undo()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.speed" title="turtle.speed"><code class="xref py py-func docutils literal notranslate"><span class="pre">speed()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Tell Turtle’s state</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.position" title="turtle.position"><code class="xref py py-func docutils literal notranslate"><span class="pre">position()</span></code></a> | <a class="reference internal" href="#turtle.pos" title="turtle.pos"><code class="xref py py-func docutils literal notranslate"><span class="pre">pos()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.towards" title="turtle.towards"><code class="xref py py-func docutils literal notranslate"><span class="pre">towards()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.xcor" title="turtle.xcor"><code class="xref py py-func docutils literal notranslate"><span class="pre">xcor()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.ycor" title="turtle.ycor"><code class="xref py py-func docutils literal notranslate"><span class="pre">ycor()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.heading" title="turtle.heading"><code class="xref py py-func docutils literal notranslate"><span class="pre">heading()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.distance" title="turtle.distance"><code class="xref py py-func docutils literal notranslate"><span class="pre">distance()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Setting and measurement</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.degrees" title="turtle.degrees"><code class="xref py py-func docutils literal notranslate"><span class="pre">degrees()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.radians" title="turtle.radians"><code class="xref py py-func docutils literal notranslate"><span class="pre">radians()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</dd>
|
|||
|
<dt>Pen control</dt><dd><dl>
|
|||
|
<dt>Drawing state</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.pendown" title="turtle.pendown"><code class="xref py py-func docutils literal notranslate"><span class="pre">pendown()</span></code></a> | <a class="reference internal" href="#turtle.pd" title="turtle.pd"><code class="xref py py-func docutils literal notranslate"><span class="pre">pd()</span></code></a> | <a class="reference internal" href="#turtle.down" title="turtle.down"><code class="xref py py-func docutils literal notranslate"><span class="pre">down()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.penup" title="turtle.penup"><code class="xref py py-func docutils literal notranslate"><span class="pre">penup()</span></code></a> | <a class="reference internal" href="#turtle.pu" title="turtle.pu"><code class="xref py py-func docutils literal notranslate"><span class="pre">pu()</span></code></a> | <a class="reference internal" href="#turtle.up" title="turtle.up"><code class="xref py py-func docutils literal notranslate"><span class="pre">up()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.pensize" title="turtle.pensize"><code class="xref py py-func docutils literal notranslate"><span class="pre">pensize()</span></code></a> | <a class="reference internal" href="#turtle.width" title="turtle.width"><code class="xref py py-func docutils literal notranslate"><span class="pre">width()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.pen" title="turtle.pen"><code class="xref py py-func docutils literal notranslate"><span class="pre">pen()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.isdown" title="turtle.isdown"><code class="xref py py-func docutils literal notranslate"><span class="pre">isdown()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Color control</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.color" title="turtle.color"><code class="xref py py-func docutils literal notranslate"><span class="pre">color()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.pencolor" title="turtle.pencolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">pencolor()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.fillcolor" title="turtle.fillcolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">fillcolor()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Filling</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.filling" title="turtle.filling"><code class="xref py py-func docutils literal notranslate"><span class="pre">filling()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.begin_fill" title="turtle.begin_fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">begin_fill()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.end_fill" title="turtle.end_fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">end_fill()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>More drawing control</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.reset" title="turtle.reset"><code class="xref py py-func docutils literal notranslate"><span class="pre">reset()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.clear" title="turtle.clear"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.write" title="turtle.write"><code class="xref py py-func docutils literal notranslate"><span class="pre">write()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</dd>
|
|||
|
<dt>Turtle state</dt><dd><dl>
|
|||
|
<dt>Visibility</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.showturtle" title="turtle.showturtle"><code class="xref py py-func docutils literal notranslate"><span class="pre">showturtle()</span></code></a> | <a class="reference internal" href="#turtle.st" title="turtle.st"><code class="xref py py-func docutils literal notranslate"><span class="pre">st()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.hideturtle" title="turtle.hideturtle"><code class="xref py py-func docutils literal notranslate"><span class="pre">hideturtle()</span></code></a> | <a class="reference internal" href="#turtle.ht" title="turtle.ht"><code class="xref py py-func docutils literal notranslate"><span class="pre">ht()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.isvisible" title="turtle.isvisible"><code class="xref py py-func docutils literal notranslate"><span class="pre">isvisible()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Appearance</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.shape" title="turtle.shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">shape()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.resizemode" title="turtle.resizemode"><code class="xref py py-func docutils literal notranslate"><span class="pre">resizemode()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.shapesize" title="turtle.shapesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapesize()</span></code></a> | <a class="reference internal" href="#turtle.turtlesize" title="turtle.turtlesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtlesize()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.shearfactor" title="turtle.shearfactor"><code class="xref py py-func docutils literal notranslate"><span class="pre">shearfactor()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.settiltangle" title="turtle.settiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">settiltangle()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.tiltangle" title="turtle.tiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">tiltangle()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.tilt" title="turtle.tilt"><code class="xref py py-func docutils literal notranslate"><span class="pre">tilt()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.shapetransform" title="turtle.shapetransform"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapetransform()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.get_shapepoly" title="turtle.get_shapepoly"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_shapepoly()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</dd>
|
|||
|
<dt>Using events</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.onclick" title="turtle.onclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">onclick()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.onrelease" title="turtle.onrelease"><code class="xref py py-func docutils literal notranslate"><span class="pre">onrelease()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.ondrag" title="turtle.ondrag"><code class="xref py py-func docutils literal notranslate"><span class="pre">ondrag()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Special Turtle methods</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.begin_poly" title="turtle.begin_poly"><code class="xref py py-func docutils literal notranslate"><span class="pre">begin_poly()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.end_poly" title="turtle.end_poly"><code class="xref py py-func docutils literal notranslate"><span class="pre">end_poly()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.get_poly" title="turtle.get_poly"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_poly()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.clone" title="turtle.clone"><code class="xref py py-func docutils literal notranslate"><span class="pre">clone()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.getturtle" title="turtle.getturtle"><code class="xref py py-func docutils literal notranslate"><span class="pre">getturtle()</span></code></a> | <a class="reference internal" href="#turtle.getpen" title="turtle.getpen"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpen()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.getscreen" title="turtle.getscreen"><code class="xref py py-func docutils literal notranslate"><span class="pre">getscreen()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.setundobuffer" title="turtle.setundobuffer"><code class="xref py py-func docutils literal notranslate"><span class="pre">setundobuffer()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.undobufferentries" title="turtle.undobufferentries"><code class="xref py py-func docutils literal notranslate"><span class="pre">undobufferentries()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
<div class="section" id="methods-of-turtlescreen-screen">
|
|||
|
<h3>Methods of TurtleScreen/Screen<a class="headerlink" href="#methods-of-turtlescreen-screen" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl>
|
|||
|
<dt>Window control</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.bgcolor" title="turtle.bgcolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">bgcolor()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.bgpic" title="turtle.bgpic"><code class="xref py py-func docutils literal notranslate"><span class="pre">bgpic()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.clear" title="turtle.clear"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear()</span></code></a> | <a class="reference internal" href="#turtle.clearscreen" title="turtle.clearscreen"><code class="xref py py-func docutils literal notranslate"><span class="pre">clearscreen()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.reset" title="turtle.reset"><code class="xref py py-func docutils literal notranslate"><span class="pre">reset()</span></code></a> | <a class="reference internal" href="#turtle.resetscreen" title="turtle.resetscreen"><code class="xref py py-func docutils literal notranslate"><span class="pre">resetscreen()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.screensize" title="turtle.screensize"><code class="xref py py-func docutils literal notranslate"><span class="pre">screensize()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.setworldcoordinates" title="turtle.setworldcoordinates"><code class="xref py py-func docutils literal notranslate"><span class="pre">setworldcoordinates()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Animation control</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.delay" title="turtle.delay"><code class="xref py py-func docutils literal notranslate"><span class="pre">delay()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.tracer" title="turtle.tracer"><code class="xref py py-func docutils literal notranslate"><span class="pre">tracer()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.update" title="turtle.update"><code class="xref py py-func docutils literal notranslate"><span class="pre">update()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Using screen events</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.onkey" title="turtle.onkey"><code class="xref py py-func docutils literal notranslate"><span class="pre">onkey()</span></code></a> | <a class="reference internal" href="#turtle.onkeyrelease" title="turtle.onkeyrelease"><code class="xref py py-func docutils literal notranslate"><span class="pre">onkeyrelease()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.onkeypress" title="turtle.onkeypress"><code class="xref py py-func docutils literal notranslate"><span class="pre">onkeypress()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.onclick" title="turtle.onclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">onclick()</span></code></a> | <a class="reference internal" href="#turtle.onscreenclick" title="turtle.onscreenclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">onscreenclick()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.ontimer" title="turtle.ontimer"><code class="xref py py-func docutils literal notranslate"><span class="pre">ontimer()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.mainloop" title="turtle.mainloop"><code class="xref py py-func docutils literal notranslate"><span class="pre">mainloop()</span></code></a> | <a class="reference internal" href="#turtle.done" title="turtle.done"><code class="xref py py-func docutils literal notranslate"><span class="pre">done()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Settings and special methods</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.getcanvas" title="turtle.getcanvas"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcanvas()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.getshapes" title="turtle.getshapes"><code class="xref py py-func docutils literal notranslate"><span class="pre">getshapes()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.register_shape" title="turtle.register_shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_shape()</span></code></a> | <a class="reference internal" href="#turtle.addshape" title="turtle.addshape"><code class="xref py py-func docutils literal notranslate"><span class="pre">addshape()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.turtles" title="turtle.turtles"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtles()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.window_height" title="turtle.window_height"><code class="xref py py-func docutils literal notranslate"><span class="pre">window_height()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.window_width" title="turtle.window_width"><code class="xref py py-func docutils literal notranslate"><span class="pre">window_width()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Input methods</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.textinput" title="turtle.textinput"><code class="xref py py-func docutils literal notranslate"><span class="pre">textinput()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.numinput" title="turtle.numinput"><code class="xref py py-func docutils literal notranslate"><span class="pre">numinput()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
<dt>Methods specific to Screen</dt><dd><div class="line-block">
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.bye" title="turtle.bye"><code class="xref py py-func docutils literal notranslate"><span class="pre">bye()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.exitonclick" title="turtle.exitonclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">exitonclick()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.setup" title="turtle.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a></div>
|
|||
|
<div class="line"><a class="reference internal" href="#turtle.title" title="turtle.title"><code class="xref py py-func docutils literal notranslate"><span class="pre">title()</span></code></a></div>
|
|||
|
</div>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="methods-of-rawturtle-turtle-and-corresponding-functions">
|
|||
|
<h2>Methods of RawTurtle/Turtle and corresponding functions<a class="headerlink" href="#methods-of-rawturtle-turtle-and-corresponding-functions" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>Most of the examples in this section refer to a Turtle instance called
|
|||
|
<code class="docutils literal notranslate"><span class="pre">turtle</span></code>.</p>
|
|||
|
<div class="section" id="turtle-motion">
|
|||
|
<h3>Turtle motion<a class="headerlink" href="#turtle-motion" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.forward">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">forward</code><span class="sig-paren">(</span><em>distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.forward" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.fd">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">fd</code><span class="sig-paren">(</span><em>distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.fd" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>distance</strong> – a number (integer or float)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Move the turtle forward by the specified <em>distance</em>, in the direction the
|
|||
|
turtle is headed.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(25.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="o">-</span><span class="mi">75</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(-50.00,0.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.back">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">back</code><span class="sig-paren">(</span><em>distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.back" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.bk">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">bk</code><span class="sig-paren">(</span><em>distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bk" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.backward">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">backward</code><span class="sig-paren">(</span><em>distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.backward" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>distance</strong> – a number</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Move the turtle backward by <em>distance</em>, opposite to the direction the
|
|||
|
turtle is headed. Do not change the turtle’s heading.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">backward</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(-30.00,0.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.right">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">right</code><span class="sig-paren">(</span><em>angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.right" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.rt">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">rt</code><span class="sig-paren">(</span><em>angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.rt" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>angle</strong> – a number (integer or float)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Turn turtle right by <em>angle</em> units. (Units are by default degrees, but
|
|||
|
can be set via the <a class="reference internal" href="#turtle.degrees" title="turtle.degrees"><code class="xref py py-func docutils literal notranslate"><span class="pre">degrees()</span></code></a> and <a class="reference internal" href="#turtle.radians" title="turtle.radians"><code class="xref py py-func docutils literal notranslate"><span class="pre">radians()</span></code></a> functions.) Angle
|
|||
|
orientation depends on the turtle mode, see <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">22.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">right</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">337.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.left">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">left</code><span class="sig-paren">(</span><em>angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.left" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.lt">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">lt</code><span class="sig-paren">(</span><em>angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.lt" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>angle</strong> – a number (integer or float)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Turn turtle left by <em>angle</em> units. (Units are by default degrees, but
|
|||
|
can be set via the <a class="reference internal" href="#turtle.degrees" title="turtle.degrees"><code class="xref py py-func docutils literal notranslate"><span class="pre">degrees()</span></code></a> and <a class="reference internal" href="#turtle.radians" title="turtle.radians"><code class="xref py py-func docutils literal notranslate"><span class="pre">radians()</span></code></a> functions.) Angle
|
|||
|
orientation depends on the turtle mode, see <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">22.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">67.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.goto">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">goto</code><span class="sig-paren">(</span><em>x</em>, <em>y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.goto" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.setpos">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setpos</code><span class="sig-paren">(</span><em>x</em>, <em>y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setpos" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.setposition">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setposition</code><span class="sig-paren">(</span><em>x</em>, <em>y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setposition" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>x</strong> – a number or a pair/vector of numbers</p></li>
|
|||
|
<li><p><strong>y</strong> – a number or <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>If <em>y</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <em>x</em> must be a pair of coordinates or a <a class="reference internal" href="#turtle.Vec2D" title="turtle.Vec2D"><code class="xref py py-class docutils literal notranslate"><span class="pre">Vec2D</span></code></a>
|
|||
|
(e.g. as returned by <a class="reference internal" href="#turtle.pos" title="turtle.pos"><code class="xref py py-func docutils literal notranslate"><span class="pre">pos()</span></code></a>).</p>
|
|||
|
<p>Move turtle to an absolute position. If the pen is down, draw line. Do
|
|||
|
not change the turtle’s orientation.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">tp</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">tp</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">setpos</span><span class="p">(</span><span class="mi">60</span><span class="p">,</span><span class="mi">30</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
|
|||
|
<span class="go">(60.00,30.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">setpos</span><span class="p">((</span><span class="mi">20</span><span class="p">,</span><span class="mi">80</span><span class="p">))</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
|
|||
|
<span class="go">(20.00,80.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">setpos</span><span class="p">(</span><span class="n">tp</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.setx">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setx</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setx" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>x</strong> – a number (integer or float)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set the turtle’s first coordinate to <em>x</em>, leave second coordinate
|
|||
|
unchanged.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,240.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">setx</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(10.00,240.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.sety">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">sety</code><span class="sig-paren">(</span><em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.sety" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>y</strong> – a number (integer or float)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set the turtle’s second coordinate to <em>y</em>, leave first coordinate unchanged.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,40.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">sety</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,-10.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.setheading">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setheading</code><span class="sig-paren">(</span><em>to_angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setheading" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.seth">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">seth</code><span class="sig-paren">(</span><em>to_angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.seth" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>to_angle</strong> – a number (integer or float)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set the orientation of the turtle to <em>to_angle</em>. Here are some common
|
|||
|
directions in degrees:</p>
|
|||
|
<table class="docutils align-center">
|
|||
|
<colgroup>
|
|||
|
<col style="width: 49%" />
|
|||
|
<col style="width: 51%" />
|
|||
|
</colgroup>
|
|||
|
<thead>
|
|||
|
<tr class="row-odd"><th class="head"><p>standard mode</p></th>
|
|||
|
<th class="head"><p>logo mode</p></th>
|
|||
|
</tr>
|
|||
|
</thead>
|
|||
|
<tbody>
|
|||
|
<tr class="row-even"><td><p>0 - east</p></td>
|
|||
|
<td><p>0 - north</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>90 - north</p></td>
|
|||
|
<td><p>90 - east</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>180 - west</p></td>
|
|||
|
<td><p>180 - south</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>270 - south</p></td>
|
|||
|
<td><p>270 - west</p></td>
|
|||
|
</tr>
|
|||
|
</tbody>
|
|||
|
</table>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">setheading</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">90.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.home">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">home</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.home" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Move turtle to the origin – coordinates (0,0) – and set its heading to
|
|||
|
its start-orientation (which depends on the mode, see <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">90.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,-10.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">0.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.circle">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">circle</code><span class="sig-paren">(</span><em>radius</em>, <em>extent=None</em>, <em>steps=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.circle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>radius</strong> – a number</p></li>
|
|||
|
<li><p><strong>extent</strong> – a number (or <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p></li>
|
|||
|
<li><p><strong>steps</strong> – an integer (or <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Draw a circle with given <em>radius</em>. The center is <em>radius</em> units left of
|
|||
|
the turtle; <em>extent</em> – an angle – determines which part of the circle
|
|||
|
is drawn. If <em>extent</em> is not given, draw the entire circle. If <em>extent</em>
|
|||
|
is not a full circle, one endpoint of the arc is the current pen
|
|||
|
position. Draw the arc in counterclockwise direction if <em>radius</em> is
|
|||
|
positive, otherwise in clockwise direction. Finally the direction of the
|
|||
|
turtle is changed by the amount of <em>extent</em>.</p>
|
|||
|
<p>As the circle is approximated by an inscribed regular polygon, <em>steps</em>
|
|||
|
determines the number of steps to use. If not given, it will be
|
|||
|
calculated automatically. May be used to draw regular polygons.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">0.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(-0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">0.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="mi">120</span><span class="p">,</span> <span class="mi">180</span><span class="p">)</span> <span class="c1"># draw a semicircle</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,240.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">180.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.dot">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">dot</code><span class="sig-paren">(</span><em>size=None</em>, <em>*color</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.dot" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>size</strong> – an integer >= 1 (if given)</p></li>
|
|||
|
<li><p><strong>color</strong> – a colorstring or a numeric color tuple</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Draw a circular dot with diameter <em>size</em>, using <em>color</em>. If <em>size</em> is
|
|||
|
not given, the maximum of pensize+4 and 2*pensize is used.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">dot</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span> <span class="n">turtle</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">);</span> <span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(100.00,-0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">0.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.stamp">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">stamp</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.stamp" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Stamp a copy of the turtle shape onto the canvas at the current turtle
|
|||
|
position. Return a stamp_id for that stamp, which can be used to delete
|
|||
|
it by calling <code class="docutils literal notranslate"><span class="pre">clearstamp(stamp_id)</span></code>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">"blue"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">stamp</span><span class="p">()</span>
|
|||
|
<span class="go">11</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.clearstamp">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">clearstamp</code><span class="sig-paren">(</span><em>stampid</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clearstamp" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>stampid</strong> – an integer, must be return value of previous
|
|||
|
<a class="reference internal" href="#turtle.stamp" title="turtle.stamp"><code class="xref py py-func docutils literal notranslate"><span class="pre">stamp()</span></code></a> call</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Delete stamp with given <em>stampid</em>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(150.00,-0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">"blue"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">astamp</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">stamp</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(200.00,-0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamp</span><span class="p">(</span><span class="n">astamp</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(200.00,-0.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.clearstamps">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">clearstamps</code><span class="sig-paren">(</span><em>n=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clearstamps" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>n</strong> – an integer (or <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Delete all or first/last <em>n</em> of turtle’s stamps. If <em>n</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, delete
|
|||
|
all stamps, if <em>n</em> > 0 delete first <em>n</em> stamps, else if <em>n</em> < 0 delete
|
|||
|
last <em>n</em> stamps.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">turtle</span><span class="o">.</span><span class="n">stamp</span><span class="p">();</span> <span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
|
|||
|
<span class="go">13</span>
|
|||
|
<span class="go">14</span>
|
|||
|
<span class="go">15</span>
|
|||
|
<span class="go">16</span>
|
|||
|
<span class="go">17</span>
|
|||
|
<span class="go">18</span>
|
|||
|
<span class="go">19</span>
|
|||
|
<span class="go">20</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamps</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamps</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamps</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.undo">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">undo</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.undo" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Undo (repeatedly) the last turtle action(s). Number of available
|
|||
|
undo actions is determined by the size of the undobuffer.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span> <span class="n">turtle</span><span class="o">.</span><span class="n">lt</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">turtle</span><span class="o">.</span><span class="n">undo</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.speed">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">speed</code><span class="sig-paren">(</span><em>speed=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.speed" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>speed</strong> – an integer in the range 0..10 or a speedstring (see below)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set the turtle’s speed to an integer value in the range 0..10. If no
|
|||
|
argument is given, return current speed.</p>
|
|||
|
<p>If input is a number greater than 10 or smaller than 0.5, speed is set
|
|||
|
to 0. Speedstrings are mapped to speedvalues as follows:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>“fastest”: 0</p></li>
|
|||
|
<li><p>“fast”: 10</p></li>
|
|||
|
<li><p>“normal”: 6</p></li>
|
|||
|
<li><p>“slow”: 3</p></li>
|
|||
|
<li><p>“slowest”: 1</p></li>
|
|||
|
</ul>
|
|||
|
<p>Speeds from 1 to 10 enforce increasingly faster animation of line drawing
|
|||
|
and turtle turning.</p>
|
|||
|
<p>Attention: <em>speed</em> = 0 means that <em>no</em> animation takes
|
|||
|
place. forward/back makes turtle jump and likewise left/right make the
|
|||
|
turtle turn instantly.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">()</span>
|
|||
|
<span class="go">3</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">(</span><span class="s1">'normal'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">()</span>
|
|||
|
<span class="go">6</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">()</span>
|
|||
|
<span class="go">9</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="tell-turtle-s-state">
|
|||
|
<h3>Tell Turtle’s state<a class="headerlink" href="#tell-turtle-s-state" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.position">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">position</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.position" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.pos">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pos</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pos" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the turtle’s current location (x,y) (as a <a class="reference internal" href="#turtle.Vec2D" title="turtle.Vec2D"><code class="xref py py-class docutils literal notranslate"><span class="pre">Vec2D</span></code></a> vector).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
|
|||
|
<span class="go">(440.00,-0.00)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.towards">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">towards</code><span class="sig-paren">(</span><em>x</em>, <em>y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.towards" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>x</strong> – a number or a pair/vector of numbers or a turtle instance</p></li>
|
|||
|
<li><p><strong>y</strong> – a number if <em>x</em> is a number, else <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Return the angle between the line from turtle position to position specified
|
|||
|
by (x,y), the vector or the other turtle. This depends on the turtle’s start
|
|||
|
orientation which depends on the mode - “standard”/”world” or “logo”).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">towards</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
|
|||
|
<span class="go">225.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.xcor">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">xcor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.xcor" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the turtle’s x coordinate.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
|
|||
|
<span class="go">(64.28,76.60)</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">xcor</span><span class="p">(),</span> <span class="mi">5</span><span class="p">))</span>
|
|||
|
<span class="go">64.27876</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.ycor">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">ycor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ycor" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the turtle’s y coordinate.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">())</span>
|
|||
|
<span class="go">(50.00,86.60)</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">ycor</span><span class="p">(),</span> <span class="mi">5</span><span class="p">))</span>
|
|||
|
<span class="go">86.60254</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.heading">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">heading</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.heading" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the turtle’s current heading (value depends on the turtle mode, see
|
|||
|
<a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">67</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">67.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.distance">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">distance</code><span class="sig-paren">(</span><em>x</em>, <em>y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.distance" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>x</strong> – a number or a pair/vector of numbers or a turtle instance</p></li>
|
|||
|
<li><p><strong>y</strong> – a number if <em>x</em> is a number, else <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Return the distance from the turtle to (x,y), the given vector, or the given
|
|||
|
other turtle, in turtle step units.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span><span class="mi">40</span><span class="p">)</span>
|
|||
|
<span class="go">50.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">distance</span><span class="p">((</span><span class="mi">30</span><span class="p">,</span><span class="mi">40</span><span class="p">))</span>
|
|||
|
<span class="go">50.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">joe</span> <span class="o">=</span> <span class="n">Turtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">joe</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">77</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="n">joe</span><span class="p">)</span>
|
|||
|
<span class="go">77.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="settings-for-measurement">
|
|||
|
<h3>Settings for measurement<a class="headerlink" href="#settings-for-measurement" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.degrees">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">degrees</code><span class="sig-paren">(</span><em>fullcircle=360.0</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.degrees" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>fullcircle</strong> – a number</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set angle measurement units, i.e. set number of “degrees” for a full circle.
|
|||
|
Default value is 360 degrees.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">90.0</span>
|
|||
|
|
|||
|
<span class="go">Change angle measurement unit to grad (also known as gon,</span>
|
|||
|
<span class="go">grade, or gradian and equals 1/100-th of the right angle.)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">degrees</span><span class="p">(</span><span class="mf">400.0</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">100.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">degrees</span><span class="p">(</span><span class="mi">360</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">90.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.radians">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">radians</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.radians" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Set the angle measurement units to radians. Equivalent to
|
|||
|
<code class="docutils literal notranslate"><span class="pre">degrees(2*math.pi)</span></code>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">90.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">radians</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">1.5707963267948966</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="pen-control">
|
|||
|
<h3>Pen control<a class="headerlink" href="#pen-control" title="Permalink to this headline">¶</a></h3>
|
|||
|
<div class="section" id="drawing-state">
|
|||
|
<h4>Drawing state<a class="headerlink" href="#drawing-state" title="Permalink to this headline">¶</a></h4>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.pendown">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pendown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pendown" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.pd">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pd</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pd" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.down">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">down</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.down" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Pull the pen down – drawing when moving.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.penup">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">penup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.penup" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.pu">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pu</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pu" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.up">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">up</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.up" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Pull the pen up – no drawing when moving.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.pensize">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pensize</code><span class="sig-paren">(</span><em>width=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pensize" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.width">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">width</code><span class="sig-paren">(</span><em>width=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.width" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>width</strong> – a positive number</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set the line thickness to <em>width</em> or return it. If resizemode is set to
|
|||
|
“auto” and turtleshape is a polygon, that polygon is drawn with the same line
|
|||
|
thickness. If no argument is given, the current pensize is returned.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">()</span>
|
|||
|
<span class="go">1</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="c1"># from here on lines of width 10 are drawn</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.pen">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pen</code><span class="sig-paren">(</span><em>pen=None</em>, <em>**pendict</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>pen</strong> – a dictionary with some or all of the below listed keys</p></li>
|
|||
|
<li><p><strong>pendict</strong> – one or more keyword-arguments with the below listed keys as keywords</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Return or set the pen’s attributes in a “pen-dictionary” with the following
|
|||
|
key/value pairs:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>“shown”: True/False</p></li>
|
|||
|
<li><p>“pendown”: True/False</p></li>
|
|||
|
<li><p>“pencolor”: color-string or color-tuple</p></li>
|
|||
|
<li><p>“fillcolor”: color-string or color-tuple</p></li>
|
|||
|
<li><p>“pensize”: positive number</p></li>
|
|||
|
<li><p>“speed”: number in range 0..10</p></li>
|
|||
|
<li><p>“resizemode”: “auto” or “user” or “noresize”</p></li>
|
|||
|
<li><p>“stretchfactor”: (positive number, positive number)</p></li>
|
|||
|
<li><p>“outline”: positive number</p></li>
|
|||
|
<li><p>“tilt”: number</p></li>
|
|||
|
</ul>
|
|||
|
<p>This dictionary can be used as argument for a subsequent call to <a class="reference internal" href="#turtle.pen" title="turtle.pen"><code class="xref py py-func docutils literal notranslate"><span class="pre">pen()</span></code></a>
|
|||
|
to restore the former pen-state. Moreover one or more of these attributes
|
|||
|
can be provided as keyword-arguments. This can be used to set several pen
|
|||
|
attributes in one statement.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">(</span><span class="n">fillcolor</span><span class="o">=</span><span class="s2">"black"</span><span class="p">,</span> <span class="n">pencolor</span><span class="o">=</span><span class="s2">"red"</span><span class="p">,</span> <span class="n">pensize</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
|
|||
|
<span class="go">[('fillcolor', 'black'), ('outline', 1), ('pencolor', 'red'),</span>
|
|||
|
<span class="go"> ('pendown', True), ('pensize', 10), ('resizemode', 'noresize'),</span>
|
|||
|
<span class="go"> ('shearfactor', 0.0), ('shown', True), ('speed', 9),</span>
|
|||
|
<span class="go"> ('stretchfactor', (1.0, 1.0)), ('tilt', 0.0)]</span>
|
|||
|
<span class="gp">>>> </span><span class="n">penstate</span><span class="o">=</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">"yellow"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">penup</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">())[:</span><span class="mi">3</span><span class="p">]</span>
|
|||
|
<span class="go">[('fillcolor', ''), ('outline', 1), ('pencolor', 'yellow')]</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">(</span><span class="n">penstate</span><span class="p">,</span> <span class="n">fillcolor</span><span class="o">=</span><span class="s2">"green"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">())[:</span><span class="mi">3</span><span class="p">]</span>
|
|||
|
<span class="go">[('fillcolor', 'green'), ('outline', 1), ('pencolor', 'red')]</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.isdown">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">isdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.isdown" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if pen is down, <code class="docutils literal notranslate"><span class="pre">False</span></code> if it’s up.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">penup</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">isdown</span><span class="p">()</span>
|
|||
|
<span class="go">False</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pendown</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">isdown</span><span class="p">()</span>
|
|||
|
<span class="go">True</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="color-control">
|
|||
|
<h4>Color control<a class="headerlink" href="#color-control" title="Permalink to this headline">¶</a></h4>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.pencolor">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">pencolor</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pencolor" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return or set the pencolor.</p>
|
|||
|
<p>Four input formats are allowed:</p>
|
|||
|
<dl>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">pencolor()</span></code></dt><dd><p>Return the current pencolor as color specification string or
|
|||
|
as a tuple (see example). May be used as input to another
|
|||
|
color/pencolor/fillcolor call.</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">pencolor(colorstring)</span></code></dt><dd><p>Set pencolor to <em>colorstring</em>, which is a Tk color specification string,
|
|||
|
such as <code class="docutils literal notranslate"><span class="pre">"red"</span></code>, <code class="docutils literal notranslate"><span class="pre">"yellow"</span></code>, or <code class="docutils literal notranslate"><span class="pre">"#33cc8c"</span></code>.</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">pencolor((r,</span> <span class="pre">g,</span> <span class="pre">b))</span></code></dt><dd><p>Set pencolor to the RGB color represented by the tuple of <em>r</em>, <em>g</em>, and
|
|||
|
<em>b</em>. Each of <em>r</em>, <em>g</em>, and <em>b</em> must be in the range 0..colormode, where
|
|||
|
colormode is either 1.0 or 255 (see <a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a>).</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">pencolor(r,</span> <span class="pre">g,</span> <span class="pre">b)</span></code></dt><dd><blockquote>
|
|||
|
<div><p>Set pencolor to the RGB color represented by <em>r</em>, <em>g</em>, and <em>b</em>. Each of
|
|||
|
<em>r</em>, <em>g</em>, and <em>b</em> must be in the range 0..colormode.</p>
|
|||
|
</div></blockquote>
|
|||
|
<p>If turtleshape is a polygon, the outline of that polygon is drawn with the
|
|||
|
newly set pencolor.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">colormode</span><span class="p">()</span>
|
|||
|
<span class="go">1.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
|
|||
|
<span class="go">'red'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="s2">"brown"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
|
|||
|
<span class="go">'brown'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">tup</span> <span class="o">=</span> <span class="p">(</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.55</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="n">tup</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
|
|||
|
<span class="go">(0.2, 0.8, 0.5490196078431373)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">colormode</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
|
|||
|
<span class="go">(51.0, 204.0, 140.0)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="s1">'#32c18f'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
|
|||
|
<span class="go">(50.0, 193.0, 143.0)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.fillcolor">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">fillcolor</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.fillcolor" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return or set the fillcolor.</p>
|
|||
|
<p>Four input formats are allowed:</p>
|
|||
|
<dl>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor()</span></code></dt><dd><p>Return the current fillcolor as color specification string, possibly
|
|||
|
in tuple format (see example). May be used as input to another
|
|||
|
color/pencolor/fillcolor call.</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor(colorstring)</span></code></dt><dd><p>Set fillcolor to <em>colorstring</em>, which is a Tk color specification string,
|
|||
|
such as <code class="docutils literal notranslate"><span class="pre">"red"</span></code>, <code class="docutils literal notranslate"><span class="pre">"yellow"</span></code>, or <code class="docutils literal notranslate"><span class="pre">"#33cc8c"</span></code>.</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor((r,</span> <span class="pre">g,</span> <span class="pre">b))</span></code></dt><dd><p>Set fillcolor to the RGB color represented by the tuple of <em>r</em>, <em>g</em>, and
|
|||
|
<em>b</em>. Each of <em>r</em>, <em>g</em>, and <em>b</em> must be in the range 0..colormode, where
|
|||
|
colormode is either 1.0 or 255 (see <a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a>).</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor(r,</span> <span class="pre">g,</span> <span class="pre">b)</span></code></dt><dd><blockquote>
|
|||
|
<div><p>Set fillcolor to the RGB color represented by <em>r</em>, <em>g</em>, and <em>b</em>. Each of
|
|||
|
<em>r</em>, <em>g</em>, and <em>b</em> must be in the range 0..colormode.</p>
|
|||
|
</div></blockquote>
|
|||
|
<p>If turtleshape is a polygon, the interior of that polygon is drawn
|
|||
|
with the newly set fillcolor.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s2">"violet"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">()</span>
|
|||
|
<span class="go">'violet'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
|
|||
|
<span class="go">(50.0, 193.0, 143.0)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">((</span><span class="mi">50</span><span class="p">,</span> <span class="mi">193</span><span class="p">,</span> <span class="mi">143</span><span class="p">))</span> <span class="c1"># Integers, not floats</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">()</span>
|
|||
|
<span class="go">(50.0, 193.0, 143.0)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s1">'#ffffff'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">()</span>
|
|||
|
<span class="go">(255.0, 255.0, 255.0)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.color">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">color</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.color" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return or set pencolor and fillcolor.</p>
|
|||
|
<p>Several input formats are allowed. They use 0 to 3 arguments as
|
|||
|
follows:</p>
|
|||
|
<dl>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">color()</span></code></dt><dd><p>Return the current pencolor and the current fillcolor as a pair of color
|
|||
|
specification strings or tuples as returned by <a class="reference internal" href="#turtle.pencolor" title="turtle.pencolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">pencolor()</span></code></a> and
|
|||
|
<a class="reference internal" href="#turtle.fillcolor" title="turtle.fillcolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">fillcolor()</span></code></a>.</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">color(colorstring)</span></code>, <code class="docutils literal notranslate"><span class="pre">color((r,g,b))</span></code>, <code class="docutils literal notranslate"><span class="pre">color(r,g,b)</span></code></dt><dd><p>Inputs as in <a class="reference internal" href="#turtle.pencolor" title="turtle.pencolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">pencolor()</span></code></a>, set both, fillcolor and pencolor, to the
|
|||
|
given value.</p>
|
|||
|
</dd>
|
|||
|
<dt><code class="docutils literal notranslate"><span class="pre">color(colorstring1,</span> <span class="pre">colorstring2)</span></code>, <code class="docutils literal notranslate"><span class="pre">color((r1,g1,b1),</span> <span class="pre">(r2,g2,b2))</span></code></dt><dd><blockquote>
|
|||
|
<div><p>Equivalent to <code class="docutils literal notranslate"><span class="pre">pencolor(colorstring1)</span></code> and <code class="docutils literal notranslate"><span class="pre">fillcolor(colorstring2)</span></code>
|
|||
|
and analogously if the other input format is used.</p>
|
|||
|
</div></blockquote>
|
|||
|
<p>If turtleshape is a polygon, outline and interior of that polygon is drawn
|
|||
|
with the newly set colors.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">"red"</span><span class="p">,</span> <span class="s2">"green"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">()</span>
|
|||
|
<span class="go">('red', 'green')</span>
|
|||
|
<span class="gp">>>> </span><span class="n">color</span><span class="p">(</span><span class="s2">"#285078"</span><span class="p">,</span> <span class="s2">"#a0c8f0"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">color</span><span class="p">()</span>
|
|||
|
<span class="go">((40.0, 80.0, 120.0), (160.0, 200.0, 240.0))</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<p>See also: Screen method <a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a>.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="filling">
|
|||
|
<h4>Filling<a class="headerlink" href="#filling" title="Permalink to this headline">¶</a></h4>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.filling">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">filling</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.filling" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return fillstate (<code class="docutils literal notranslate"><span class="pre">True</span></code> if filling, <code class="docutils literal notranslate"><span class="pre">False</span></code> else).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">begin_fill</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="k">if</span> <span class="n">turtle</span><span class="o">.</span><span class="n">filling</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span><span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="gp">... </span> <span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.begin_fill">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">begin_fill</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.begin_fill" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>To be called just before drawing a shape to be filled.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.end_fill">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">end_fill</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.end_fill" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Fill the shape drawn after the last call to <a class="reference internal" href="#turtle.begin_fill" title="turtle.begin_fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">begin_fill()</span></code></a>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">"black"</span><span class="p">,</span> <span class="s2">"red"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">begin_fill</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">end_fill</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="more-drawing-control">
|
|||
|
<h4>More drawing control<a class="headerlink" href="#more-drawing-control" title="Permalink to this headline">¶</a></h4>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.reset">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.reset" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Delete the turtle’s drawings from the screen, re-center the turtle and set
|
|||
|
variables to the default values.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="o">-</span><span class="mi">22</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,-22.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">100.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
|
|||
|
<span class="go">(0.00,0.00)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
|
|||
|
<span class="go">0.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.clear">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clear" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Delete the turtle’s drawings from the screen. Do not move turtle. State and
|
|||
|
position of the turtle as well as drawings of other turtles are not affected.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.write">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">write</code><span class="sig-paren">(</span><em>arg</em>, <em>move=False</em>, <em>align="left"</em>, <em>font=("Arial"</em>, <em>8</em>, <em>"normal")</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.write" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>arg</strong> – object to be written to the TurtleScreen</p></li>
|
|||
|
<li><p><strong>move</strong> – True/False</p></li>
|
|||
|
<li><p><strong>align</strong> – one of the strings “left”, “center” or right”</p></li>
|
|||
|
<li><p><strong>font</strong> – a triple (fontname, fontsize, fonttype)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Write text - the string representation of <em>arg</em> - at the current turtle
|
|||
|
position according to <em>align</em> (“left”, “center” or right”) and with the given
|
|||
|
font. If <em>move</em> is true, the pen is moved to the bottom-right corner of the
|
|||
|
text. By default, <em>move</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"Home = "</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">"center"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">write</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="turtle-state">
|
|||
|
<h3>Turtle state<a class="headerlink" href="#turtle-state" title="Permalink to this headline">¶</a></h3>
|
|||
|
<div class="section" id="visibility">
|
|||
|
<h4>Visibility<a class="headerlink" href="#visibility" title="Permalink to this headline">¶</a></h4>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.hideturtle">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">hideturtle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.hideturtle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.ht">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">ht</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ht" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Make the turtle invisible. It’s a good idea to do this while you’re in the
|
|||
|
middle of doing some complex drawing, because hiding the turtle speeds up the
|
|||
|
drawing observably.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">hideturtle</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.showturtle">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">showturtle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.showturtle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.st">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">st</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.st" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Make the turtle visible.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">showturtle</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.isvisible">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">isvisible</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.isvisible" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the Turtle is shown, <code class="docutils literal notranslate"><span class="pre">False</span></code> if it’s hidden.</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">hideturtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">isvisible</span><span class="p">()</span>
|
|||
|
<span class="go">False</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">showturtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">isvisible</span><span class="p">()</span>
|
|||
|
<span class="go">True</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="appearance">
|
|||
|
<h4>Appearance<a class="headerlink" href="#appearance" title="Permalink to this headline">¶</a></h4>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.shape">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">shape</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shape" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>name</strong> – a string which is a valid shapename</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set turtle shape to shape with given <em>name</em> or, if name is not given, return
|
|||
|
name of current shape. Shape with <em>name</em> must exist in the TurtleScreen’s
|
|||
|
shape dictionary. Initially there are the following polygon shapes: “arrow”,
|
|||
|
“turtle”, “circle”, “square”, “triangle”, “classic”. To learn about how to
|
|||
|
deal with shapes see Screen method <a class="reference internal" href="#turtle.register_shape" title="turtle.register_shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_shape()</span></code></a>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">()</span>
|
|||
|
<span class="go">'classic'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"turtle"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">()</span>
|
|||
|
<span class="go">'turtle'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.resizemode">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">resizemode</code><span class="sig-paren">(</span><em>rmode=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.resizemode" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>rmode</strong> – one of the strings “auto”, “user”, “noresize”</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set resizemode to one of the values: “auto”, “user”, “noresize”. If <em>rmode</em>
|
|||
|
is not given, return current resizemode. Different resizemodes have the
|
|||
|
following effects:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>“auto”: adapts the appearance of the turtle corresponding to the value of pensize.</p></li>
|
|||
|
<li><p>“user”: adapts the appearance of the turtle according to the values of
|
|||
|
stretchfactor and outlinewidth (outline), which are set by
|
|||
|
<a class="reference internal" href="#turtle.shapesize" title="turtle.shapesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapesize()</span></code></a>.</p></li>
|
|||
|
<li><p>“noresize”: no adaption of the turtle’s appearance takes place.</p></li>
|
|||
|
</ul>
|
|||
|
<p>resizemode(“user”) is called by <a class="reference internal" href="#turtle.shapesize" title="turtle.shapesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapesize()</span></code></a> when used with arguments.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">()</span>
|
|||
|
<span class="go">'noresize'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">(</span><span class="s2">"auto"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">()</span>
|
|||
|
<span class="go">'auto'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.shapesize">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">shapesize</code><span class="sig-paren">(</span><em>stretch_wid=None</em>, <em>stretch_len=None</em>, <em>outline=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shapesize" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.turtlesize">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">turtlesize</code><span class="sig-paren">(</span><em>stretch_wid=None</em>, <em>stretch_len=None</em>, <em>outline=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.turtlesize" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>stretch_wid</strong> – positive number</p></li>
|
|||
|
<li><p><strong>stretch_len</strong> – positive number</p></li>
|
|||
|
<li><p><strong>outline</strong> – positive number</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Return or set the pen’s attributes x/y-stretchfactors and/or outline. Set
|
|||
|
resizemode to “user”. If and only if resizemode is set to “user”, the turtle
|
|||
|
will be displayed stretched according to its stretchfactors: <em>stretch_wid</em> is
|
|||
|
stretchfactor perpendicular to its orientation, <em>stretch_len</em> is
|
|||
|
stretchfactor in direction of its orientation, <em>outline</em> determines the width
|
|||
|
of the shapes’s outline.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">()</span>
|
|||
|
<span class="go">(1.0, 1.0, 1)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">(</span><span class="s2">"user"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">12</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">()</span>
|
|||
|
<span class="go">(5, 5, 12)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">()</span>
|
|||
|
<span class="go">(5, 5, 8)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.shearfactor">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">shearfactor</code><span class="sig-paren">(</span><em>shear=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shearfactor" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>shear</strong> – number (optional)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set or return the current shearfactor. Shear the turtleshape according to
|
|||
|
the given shearfactor shear, which is the tangent of the shear angle.
|
|||
|
Do <em>not</em> change the turtle’s heading (direction of movement).
|
|||
|
If shear is not given: return the current shearfactor, i. e. the
|
|||
|
tangent of the shear angle, by which lines parallel to the
|
|||
|
heading of the turtle are sheared.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"circle"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shearfactor</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shearfactor</span><span class="p">()</span>
|
|||
|
<span class="go">0.5</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.tilt">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">tilt</code><span class="sig-paren">(</span><em>angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.tilt" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>angle</strong> – a number</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Rotate the turtleshape by <em>angle</em> from its current tilt-angle, but do <em>not</em>
|
|||
|
change the turtle’s heading (direction of movement).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"circle"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">tilt</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">tilt</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.settiltangle">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">settiltangle</code><span class="sig-paren">(</span><em>angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.settiltangle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>angle</strong> – a number</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Rotate the turtleshape to point in the direction specified by <em>angle</em>,
|
|||
|
regardless of its current tilt-angle. <em>Do not</em> change the turtle’s heading
|
|||
|
(direction of movement).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"circle"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">settiltangle</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">settiltangle</span><span class="p">(</span><span class="o">-</span><span class="mi">45</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="deprecated">
|
|||
|
<p><span class="versionmodified deprecated">Deprecated since version 3.1.</span></p>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.tiltangle">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">tiltangle</code><span class="sig-paren">(</span><em>angle=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.tiltangle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>angle</strong> – a number (optional)</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set or return the current tilt-angle. If angle is given, rotate the
|
|||
|
turtleshape to point in the direction specified by angle,
|
|||
|
regardless of its current tilt-angle. Do <em>not</em> change the turtle’s
|
|||
|
heading (direction of movement).
|
|||
|
If angle is not given: return the current tilt-angle, i. e. the angle
|
|||
|
between the orientation of the turtleshape and the heading of the
|
|||
|
turtle (its direction of movement).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"circle"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">tilt</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">tiltangle</span><span class="p">()</span>
|
|||
|
<span class="go">45.0</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.shapetransform">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">shapetransform</code><span class="sig-paren">(</span><em>t11=None</em>, <em>t12=None</em>, <em>t21=None</em>, <em>t22=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shapetransform" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>t11</strong> – a number (optional)</p></li>
|
|||
|
<li><p><strong>t12</strong> – a number (optional)</p></li>
|
|||
|
<li><p><strong>t21</strong> – a number (optional)</p></li>
|
|||
|
<li><p><strong>t12</strong> – a number (optional)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set or return the current transformation matrix of the turtle shape.</p>
|
|||
|
<p>If none of the matrix elements are given, return the transformation
|
|||
|
matrix as a tuple of 4 elements.
|
|||
|
Otherwise set the given elements and transform the turtleshape
|
|||
|
according to the matrix consisting of first row t11, t12 and
|
|||
|
second row t21, 22. The determinant t11 * t22 - t12 * t21 must not be
|
|||
|
zero, otherwise an error is raised.
|
|||
|
Modify stretchfactor, shearfactor and tiltangle according to the
|
|||
|
given matrix.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span> <span class="o">=</span> <span class="n">Turtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"square"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shearfactor</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapetransform</span><span class="p">()</span>
|
|||
|
<span class="go">(4.0, -1.0, -0.0, 2.0)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.get_shapepoly">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">get_shapepoly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.get_shapepoly" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the current shape polygon as tuple of coordinate pairs. This
|
|||
|
can be used to define a new shape or components of a compound shape.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">"square"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapetransform</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">get_shapepoly</span><span class="p">()</span>
|
|||
|
<span class="go">((50, -20), (30, 20), (-50, 20), (-30, -20))</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="using-events">
|
|||
|
<h3>Using events<a class="headerlink" href="#using-events" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.onclick">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onclick</code><span class="sig-paren">(</span><em>fun</em>, <em>btn=1</em>, <em>add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onclick" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with two arguments which will be called with the
|
|||
|
coordinates of the clicked point on the canvas</p></li>
|
|||
|
<li><p><strong>btn</strong> – number of the mouse-button, defaults to 1 (left mouse button)</p></li>
|
|||
|
<li><p><strong>add</strong> – <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> – if <code class="docutils literal notranslate"><span class="pre">True</span></code>, a new binding will be
|
|||
|
added, otherwise it will replace a former binding</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Bind <em>fun</em> to mouse-click events on this turtle. If <em>fun</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
|||
|
existing bindings are removed. Example for the anonymous turtle, i.e. the
|
|||
|
procedural way:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">turn</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">left</span><span class="p">(</span><span class="mi">180</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="n">onclick</span><span class="p">(</span><span class="n">turn</span><span class="p">)</span> <span class="c1"># Now clicking into the turtle will turn it.</span>
|
|||
|
<span class="gp">>>> </span><span class="n">onclick</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="c1"># event-binding will be removed</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.onrelease">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onrelease</code><span class="sig-paren">(</span><em>fun</em>, <em>btn=1</em>, <em>add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onrelease" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with two arguments which will be called with the
|
|||
|
coordinates of the clicked point on the canvas</p></li>
|
|||
|
<li><p><strong>btn</strong> – number of the mouse-button, defaults to 1 (left mouse button)</p></li>
|
|||
|
<li><p><strong>add</strong> – <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> – if <code class="docutils literal notranslate"><span class="pre">True</span></code>, a new binding will be
|
|||
|
added, otherwise it will replace a former binding</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Bind <em>fun</em> to mouse-button-release events on this turtle. If <em>fun</em> is
|
|||
|
<code class="docutils literal notranslate"><span class="pre">None</span></code>, existing bindings are removed.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">class</span> <span class="nc">MyTurtle</span><span class="p">(</span><span class="n">Turtle</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="k">def</span> <span class="nf">glow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s2">"red"</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span> <span class="k">def</span> <span class="nf">unglow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span> <span class="o">=</span> <span class="n">MyTurtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">onclick</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">glow</span><span class="p">)</span> <span class="c1"># clicking on turtle turns fillcolor red,</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">onrelease</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">unglow</span><span class="p">)</span> <span class="c1"># releasing turns it to transparent.</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.ondrag">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">ondrag</code><span class="sig-paren">(</span><em>fun</em>, <em>btn=1</em>, <em>add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ondrag" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with two arguments which will be called with the
|
|||
|
coordinates of the clicked point on the canvas</p></li>
|
|||
|
<li><p><strong>btn</strong> – number of the mouse-button, defaults to 1 (left mouse button)</p></li>
|
|||
|
<li><p><strong>add</strong> – <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> – if <code class="docutils literal notranslate"><span class="pre">True</span></code>, a new binding will be
|
|||
|
added, otherwise it will replace a former binding</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Bind <em>fun</em> to mouse-move events on this turtle. If <em>fun</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
|||
|
existing bindings are removed.</p>
|
|||
|
<p>Remark: Every sequence of mouse-move-events on a turtle is preceded by a
|
|||
|
mouse-click event on that turtle.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">ondrag</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Subsequently, clicking and dragging the Turtle will move it across
|
|||
|
the screen thereby producing handdrawings (if pen is down).</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="special-turtle-methods">
|
|||
|
<h3>Special Turtle methods<a class="headerlink" href="#special-turtle-methods" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.begin_poly">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">begin_poly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.begin_poly" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Start recording the vertices of a polygon. Current turtle position is first
|
|||
|
vertex of polygon.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.end_poly">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">end_poly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.end_poly" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Stop recording the vertices of a polygon. Current turtle position is last
|
|||
|
vertex of polygon. This will be connected with the first vertex.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.get_poly">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">get_poly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.get_poly" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the last recorded polygon.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">begin_poly</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">end_poly</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">get_poly</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">register_shape</span><span class="p">(</span><span class="s2">"myFavouriteShape"</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.clone">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">clone</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clone" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Create and return a clone of the turtle with same position, heading and
|
|||
|
turtle properties.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mick</span> <span class="o">=</span> <span class="n">Turtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">joe</span> <span class="o">=</span> <span class="n">mick</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.getturtle">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">getturtle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getturtle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.getpen">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">getpen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getpen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the Turtle object itself. Only reasonable use: as a function to
|
|||
|
return the “anonymous turtle”:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">pet</span> <span class="o">=</span> <span class="n">getturtle</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">pet</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">pet</span>
|
|||
|
<span class="go"><turtle.Turtle object at 0x...></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.getscreen">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">getscreen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getscreen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> object the turtle is drawing on.
|
|||
|
TurtleScreen methods can then be called for that object.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">ts</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">getscreen</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">ts</span>
|
|||
|
<span class="go"><turtle._Screen object at 0x...></span>
|
|||
|
<span class="gp">>>> </span><span class="n">ts</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">(</span><span class="s2">"pink"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.setundobuffer">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setundobuffer</code><span class="sig-paren">(</span><em>size</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setundobuffer" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>size</strong> – an integer or <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set or disable undobuffer. If <em>size</em> is an integer an empty undobuffer of
|
|||
|
given size is installed. <em>size</em> gives the maximum number of turtle actions
|
|||
|
that can be undone by the <a class="reference internal" href="#turtle.undo" title="turtle.undo"><code class="xref py py-func docutils literal notranslate"><span class="pre">undo()</span></code></a> method/function. If <em>size</em> is
|
|||
|
<code class="docutils literal notranslate"><span class="pre">None</span></code>, the undobuffer is disabled.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">setundobuffer</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.undobufferentries">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">undobufferentries</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.undobufferentries" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return number of entries in the undobuffer.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">while</span> <span class="n">undobufferentries</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="n">undo</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="compound-shapes">
|
|||
|
<span id="compoundshapes"></span><h3>Compound shapes<a class="headerlink" href="#compound-shapes" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>To use compound turtle shapes, which consist of several polygons of different
|
|||
|
color, you must use the helper class <a class="reference internal" href="#turtle.Shape" title="turtle.Shape"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shape</span></code></a> explicitly as described
|
|||
|
below:</p>
|
|||
|
<ol class="arabic">
|
|||
|
<li><p>Create an empty Shape object of type “compound”.</p></li>
|
|||
|
<li><p>Add as many components to this object as desired, using the
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">addcomponent()</span></code> method.</p>
|
|||
|
<p>For example:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">Shape</span><span class="p">(</span><span class="s2">"compound"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">poly1</span> <span class="o">=</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">),(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">),(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">))</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">addcomponent</span><span class="p">(</span><span class="n">poly1</span><span class="p">,</span> <span class="s2">"red"</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">poly2</span> <span class="o">=</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">),(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">))</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">addcomponent</span><span class="p">(</span><span class="n">poly2</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">,</span> <span class="s2">"red"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li><p>Now add the Shape to the Screen’s shapelist and use it:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">register_shape</span><span class="p">(</span><span class="s2">"myshape"</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">shape</span><span class="p">(</span><span class="s2">"myshape"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>The <a class="reference internal" href="#turtle.Shape" title="turtle.Shape"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shape</span></code></a> class is used internally by the <a class="reference internal" href="#turtle.register_shape" title="turtle.register_shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_shape()</span></code></a>
|
|||
|
method in different ways. The application programmer has to deal with the
|
|||
|
Shape class <em>only</em> when using compound shapes like shown above!</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="methods-of-turtlescreen-screen-and-corresponding-functions">
|
|||
|
<h2>Methods of TurtleScreen/Screen and corresponding functions<a class="headerlink" href="#methods-of-turtlescreen-screen-and-corresponding-functions" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>Most of the examples in this section refer to a TurtleScreen instance called
|
|||
|
<code class="docutils literal notranslate"><span class="pre">screen</span></code>.</p>
|
|||
|
<div class="section" id="window-control">
|
|||
|
<h3>Window control<a class="headerlink" href="#window-control" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.bgcolor">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">bgcolor</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bgcolor" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>args</strong> – a color string or three numbers in the range 0..colormode or a
|
|||
|
3-tuple of such numbers</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set or return background color of the TurtleScreen.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">(</span><span class="s2">"orange"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">()</span>
|
|||
|
<span class="go">'orange'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">(</span><span class="s2">"#800080"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">()</span>
|
|||
|
<span class="go">(128.0, 0.0, 128.0)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.bgpic">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">bgpic</code><span class="sig-paren">(</span><em>picname=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bgpic" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>picname</strong> – a string, name of a gif-file or <code class="docutils literal notranslate"><span class="pre">"nopic"</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set background image or return name of current backgroundimage. If <em>picname</em>
|
|||
|
is a filename, set the corresponding image as background. If <em>picname</em> is
|
|||
|
<code class="docutils literal notranslate"><span class="pre">"nopic"</span></code>, delete background image, if present. If <em>picname</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
|||
|
return the filename of the current backgroundimage.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgpic</span><span class="p">()</span>
|
|||
|
<span class="go">'nopic'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgpic</span><span class="p">(</span><span class="s2">"landscape.gif"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">bgpic</span><span class="p">()</span>
|
|||
|
<span class="go">"landscape.gif"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt>
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
|
|||
|
<dt id="turtle.clearscreen">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">clearscreen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clearscreen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Delete all drawings and all turtles from the TurtleScreen. Reset the now
|
|||
|
empty TurtleScreen to its initial state: white background, no background
|
|||
|
image, no event bindings and tracing on.</p>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>This TurtleScreen method is available as a global function only under the
|
|||
|
name <code class="docutils literal notranslate"><span class="pre">clearscreen</span></code>. The global function <code class="docutils literal notranslate"><span class="pre">clear</span></code> is a different one
|
|||
|
derived from the Turtle method <code class="docutils literal notranslate"><span class="pre">clear</span></code>.</p>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt>
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
|
|||
|
<dt id="turtle.resetscreen">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">resetscreen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.resetscreen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Reset all Turtles on the Screen to their initial state.</p>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>This TurtleScreen method is available as a global function only under the
|
|||
|
name <code class="docutils literal notranslate"><span class="pre">resetscreen</span></code>. The global function <code class="docutils literal notranslate"><span class="pre">reset</span></code> is another one
|
|||
|
derived from the Turtle method <code class="docutils literal notranslate"><span class="pre">reset</span></code>.</p>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.screensize">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">screensize</code><span class="sig-paren">(</span><em>canvwidth=None</em>, <em>canvheight=None</em>, <em>bg=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.screensize" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>canvwidth</strong> – positive integer, new width of canvas in pixels</p></li>
|
|||
|
<li><p><strong>canvheight</strong> – positive integer, new height of canvas in pixels</p></li>
|
|||
|
<li><p><strong>bg</strong> – colorstring or color-tuple, new background color</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>If no arguments are given, return current (canvaswidth, canvasheight). Else
|
|||
|
resize the canvas the turtles are drawing on. Do not alter the drawing
|
|||
|
window. To observe hidden parts of the canvas, use the scrollbars. With this
|
|||
|
method, one can make visible those parts of a drawing which were outside the
|
|||
|
canvas before.</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">screensize</span><span class="p">()</span>
|
|||
|
<span class="go">(400, 300)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">screensize</span><span class="p">(</span><span class="mi">2000</span><span class="p">,</span><span class="mi">1500</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">screensize</span><span class="p">()</span>
|
|||
|
<span class="go">(2000, 1500)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>e.g. to search for an erroneously escaped turtle ;-)</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.setworldcoordinates">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setworldcoordinates</code><span class="sig-paren">(</span><em>llx</em>, <em>lly</em>, <em>urx</em>, <em>ury</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setworldcoordinates" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>llx</strong> – a number, x-coordinate of lower left corner of canvas</p></li>
|
|||
|
<li><p><strong>lly</strong> – a number, y-coordinate of lower left corner of canvas</p></li>
|
|||
|
<li><p><strong>urx</strong> – a number, x-coordinate of upper right corner of canvas</p></li>
|
|||
|
<li><p><strong>ury</strong> – a number, y-coordinate of upper right corner of canvas</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set up user-defined coordinate system and switch to mode “world” if
|
|||
|
necessary. This performs a <code class="docutils literal notranslate"><span class="pre">screen.reset()</span></code>. If mode “world” is already
|
|||
|
active, all drawings are redrawn according to the new coordinates.</p>
|
|||
|
<p><strong>ATTENTION</strong>: in user-defined coordinate systems angles may appear
|
|||
|
distorted.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">setworldcoordinates</span><span class="p">(</span><span class="o">-</span><span class="mi">50</span><span class="p">,</span><span class="o">-</span><span class="mf">7.5</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span><span class="mf">7.5</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">72</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">left</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">left</span><span class="p">(</span><span class="mi">45</span><span class="p">);</span> <span class="n">fd</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># a regular octagon</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="animation-control">
|
|||
|
<h3>Animation control<a class="headerlink" href="#animation-control" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.delay">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">delay</code><span class="sig-paren">(</span><em>delay=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.delay" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>delay</strong> – positive integer</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set or return the drawing <em>delay</em> in milliseconds. (This is approximately
|
|||
|
the time interval between two consecutive canvas updates.) The longer the
|
|||
|
drawing delay, the slower the animation.</p>
|
|||
|
<p>Optional argument:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">delay</span><span class="p">()</span>
|
|||
|
<span class="go">10</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">delay</span><span class="p">()</span>
|
|||
|
<span class="go">5</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.tracer">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">tracer</code><span class="sig-paren">(</span><em>n=None</em>, <em>delay=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.tracer" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>n</strong> – nonnegative integer</p></li>
|
|||
|
<li><p><strong>delay</strong> – nonnegative integer</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Turn turtle animation on/off and set delay for update drawings. If
|
|||
|
<em>n</em> is given, only each n-th regular screen update is really
|
|||
|
performed. (Can be used to accelerate the drawing of complex
|
|||
|
graphics.) When called without arguments, returns the currently
|
|||
|
stored value of n. Second argument sets delay value (see
|
|||
|
<a class="reference internal" href="#turtle.delay" title="turtle.delay"><code class="xref py py-func docutils literal notranslate"><span class="pre">delay()</span></code></a>).</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">tracer</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">25</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">dist</span> <span class="o">=</span> <span class="mi">2</span>
|
|||
|
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">200</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">fd</span><span class="p">(</span><span class="n">dist</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span> <span class="n">rt</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span> <span class="n">dist</span> <span class="o">+=</span> <span class="mi">2</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.update">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.update" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Perform a TurtleScreen update. To be used when tracer is turned off.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<p>See also the RawTurtle/Turtle method <a class="reference internal" href="#turtle.speed" title="turtle.speed"><code class="xref py py-func docutils literal notranslate"><span class="pre">speed()</span></code></a>.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="using-screen-events">
|
|||
|
<h3>Using screen events<a class="headerlink" href="#using-screen-events" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.listen">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">listen</code><span class="sig-paren">(</span><em>xdummy=None</em>, <em>ydummy=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.listen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Set focus on TurtleScreen (in order to collect key-events). Dummy arguments
|
|||
|
are provided in order to be able to pass <a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a> to the onclick method.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.onkey">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onkey</code><span class="sig-paren">(</span><em>fun</em>, <em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onkey" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.onkeyrelease">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onkeyrelease</code><span class="sig-paren">(</span><em>fun</em>, <em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onkeyrelease" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with no arguments or <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
|
|||
|
<li><p><strong>key</strong> – a string: key (e.g. “a”) or key-symbol (e.g. “space”)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Bind <em>fun</em> to key-release event of key. If <em>fun</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, event bindings
|
|||
|
are removed. Remark: in order to be able to register key-events, TurtleScreen
|
|||
|
must have the focus. (See method <a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a>.)</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span> <span class="n">lt</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">onkey</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s2">"Up"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">listen</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.onkeypress">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onkeypress</code><span class="sig-paren">(</span><em>fun</em>, <em>key=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onkeypress" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with no arguments or <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
|
|||
|
<li><p><strong>key</strong> – a string: key (e.g. “a”) or key-symbol (e.g. “space”)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Bind <em>fun</em> to key-press event of key if key is given,
|
|||
|
or to any key-press-event if no key is given.
|
|||
|
Remark: in order to be able to register key-events, TurtleScreen
|
|||
|
must have focus. (See method <a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a>.)</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">onkey</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s2">"Up"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">listen</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt>
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onclick</code><span class="sig-paren">(</span><em>fun</em>, <em>btn=1</em>, <em>add=None</em><span class="sig-paren">)</span></dt>
|
|||
|
<dt id="turtle.onscreenclick">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">onscreenclick</code><span class="sig-paren">(</span><em>fun</em>, <em>btn=1</em>, <em>add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onscreenclick" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with two arguments which will be called with the
|
|||
|
coordinates of the clicked point on the canvas</p></li>
|
|||
|
<li><p><strong>btn</strong> – number of the mouse-button, defaults to 1 (left mouse button)</p></li>
|
|||
|
<li><p><strong>add</strong> – <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> – if <code class="docutils literal notranslate"><span class="pre">True</span></code>, a new binding will be
|
|||
|
added, otherwise it will replace a former binding</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Bind <em>fun</em> to mouse-click events on this screen. If <em>fun</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
|||
|
existing bindings are removed.</p>
|
|||
|
<p>Example for a TurtleScreen instance named <code class="docutils literal notranslate"><span class="pre">screen</span></code> and a Turtle instance
|
|||
|
named turtle:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">onclick</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">)</span> <span class="c1"># Subsequently clicking into the TurtleScreen will</span>
|
|||
|
<span class="gp">>>> </span> <span class="c1"># make the turtle move to the clicked point.</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">onclick</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="c1"># remove event binding again</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>This TurtleScreen method is available as a global function only under the
|
|||
|
name <code class="docutils literal notranslate"><span class="pre">onscreenclick</span></code>. The global function <code class="docutils literal notranslate"><span class="pre">onclick</span></code> is another one
|
|||
|
derived from the Turtle method <code class="docutils literal notranslate"><span class="pre">onclick</span></code>.</p>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.ontimer">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">ontimer</code><span class="sig-paren">(</span><em>fun</em>, <em>t=0</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ontimer" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>fun</strong> – a function with no arguments</p></li>
|
|||
|
<li><p><strong>t</strong> – a number >= 0</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Install a timer that calls <em>fun</em> after <em>t</em> milliseconds.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">running</span> <span class="o">=</span> <span class="kc">True</span>
|
|||
|
<span class="gp">>>> </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="k">if</span> <span class="n">running</span><span class="p">:</span>
|
|||
|
<span class="gp">... </span> <span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span> <span class="n">lt</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
|
|||
|
<span class="gp">... </span> <span class="n">screen</span><span class="o">.</span><span class="n">ontimer</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="mi">250</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">f</span><span class="p">()</span> <span class="c1">### makes the turtle march around</span>
|
|||
|
<span class="gp">>>> </span><span class="n">running</span> <span class="o">=</span> <span class="kc">False</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.mainloop">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">mainloop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.mainloop" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.done">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">done</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.done" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Starts event loop - calling Tkinter’s mainloop function.
|
|||
|
Must be the last statement in a turtle graphics program.
|
|||
|
Must <em>not</em> be used if a script is run from within IDLE in -n mode
|
|||
|
(No subprocess) - for interactive use of turtle graphics.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="input-methods">
|
|||
|
<h3>Input methods<a class="headerlink" href="#input-methods" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.textinput">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">textinput</code><span class="sig-paren">(</span><em>title</em>, <em>prompt</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.textinput" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>title</strong> – string</p></li>
|
|||
|
<li><p><strong>prompt</strong> – string</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Pop up a dialog window for input of a string. Parameter title is
|
|||
|
the title of the dialog window, prompt is a text mostly describing
|
|||
|
what information to input.
|
|||
|
Return the string input. If the dialog is canceled, return <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">textinput</span><span class="p">(</span><span class="s2">"NIM"</span><span class="p">,</span> <span class="s2">"Name of first player:"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.numinput">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">numinput</code><span class="sig-paren">(</span><em>title</em>, <em>prompt</em>, <em>default=None</em>, <em>minval=None</em>, <em>maxval=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.numinput" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>title</strong> – string</p></li>
|
|||
|
<li><p><strong>prompt</strong> – string</p></li>
|
|||
|
<li><p><strong>default</strong> – number (optional)</p></li>
|
|||
|
<li><p><strong>minval</strong> – number (optional)</p></li>
|
|||
|
<li><p><strong>maxval</strong> – number (optional)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Pop up a dialog window for input of a number. title is the title of the
|
|||
|
dialog window, prompt is a text mostly describing what numerical information
|
|||
|
to input. default: default value, minval: minimum value for input,
|
|||
|
maxval: maximum value for input
|
|||
|
The number input must be in the range minval .. maxval if these are
|
|||
|
given. If not, a hint is issued and the dialog remains open for
|
|||
|
correction.
|
|||
|
Return the number input. If the dialog is canceled, return <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">numinput</span><span class="p">(</span><span class="s2">"Poker"</span><span class="p">,</span> <span class="s2">"Your stakes:"</span><span class="p">,</span> <span class="mi">1000</span><span class="p">,</span> <span class="n">minval</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">maxval</span><span class="o">=</span><span class="mi">10000</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="settings-and-special-methods">
|
|||
|
<h3>Settings and special methods<a class="headerlink" href="#settings-and-special-methods" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.mode">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">mode</code><span class="sig-paren">(</span><em>mode=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.mode" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>mode</strong> – one of the strings “standard”, “logo” or “world”</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set turtle mode (“standard”, “logo” or “world”) and perform reset. If mode
|
|||
|
is not given, current mode is returned.</p>
|
|||
|
<p>Mode “standard” is compatible with old <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a>. Mode “logo” is
|
|||
|
compatible with most Logo turtle graphics. Mode “world” uses user-defined
|
|||
|
“world coordinates”. <strong>Attention</strong>: in this mode angles appear distorted if
|
|||
|
<code class="docutils literal notranslate"><span class="pre">x/y</span></code> unit-ratio doesn’t equal 1.</p>
|
|||
|
<table class="docutils align-center">
|
|||
|
<colgroup>
|
|||
|
<col style="width: 21%" />
|
|||
|
<col style="width: 45%" />
|
|||
|
<col style="width: 34%" />
|
|||
|
</colgroup>
|
|||
|
<thead>
|
|||
|
<tr class="row-odd"><th class="head"><p>Mode</p></th>
|
|||
|
<th class="head"><p>Initial turtle heading</p></th>
|
|||
|
<th class="head"><p>positive angles</p></th>
|
|||
|
</tr>
|
|||
|
</thead>
|
|||
|
<tbody>
|
|||
|
<tr class="row-even"><td><p>“standard”</p></td>
|
|||
|
<td><p>to the right (east)</p></td>
|
|||
|
<td><p>counterclockwise</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>“logo”</p></td>
|
|||
|
<td><p>upward (north)</p></td>
|
|||
|
<td><p>clockwise</p></td>
|
|||
|
</tr>
|
|||
|
</tbody>
|
|||
|
</table>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mode</span><span class="p">(</span><span class="s2">"logo"</span><span class="p">)</span> <span class="c1"># resets turtle heading to north</span>
|
|||
|
<span class="gp">>>> </span><span class="n">mode</span><span class="p">()</span>
|
|||
|
<span class="go">'logo'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.colormode">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">colormode</code><span class="sig-paren">(</span><em>cmode=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.colormode" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>cmode</strong> – one of the values 1.0 or 255</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Return the colormode or set it to 1.0 or 255. Subsequently <em>r</em>, <em>g</em>, <em>b</em>
|
|||
|
values of color triples have to be in the range 0..<em>cmode</em>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="mi">240</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span> <span class="mi">80</span><span class="p">)</span>
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
<span class="o">...</span>
|
|||
|
<span class="gr">TurtleGraphicsError</span>: <span class="n">bad color sequence: (240, 160, 80)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">()</span>
|
|||
|
<span class="go">1.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">()</span>
|
|||
|
<span class="go">255</span>
|
|||
|
<span class="gp">>>> </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="mi">240</span><span class="p">,</span><span class="mi">160</span><span class="p">,</span><span class="mi">80</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.getcanvas">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">getcanvas</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getcanvas" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the Canvas of this TurtleScreen. Useful for insiders who know what to
|
|||
|
do with a Tkinter Canvas.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">cv</span> <span class="o">=</span> <span class="n">screen</span><span class="o">.</span><span class="n">getcanvas</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">cv</span>
|
|||
|
<span class="go"><turtle.ScrolledCanvas object ...></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.getshapes">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">getshapes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getshapes" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return a list of names of all currently available turtle shapes.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">getshapes</span><span class="p">()</span>
|
|||
|
<span class="go">['arrow', 'blank', 'circle', ..., 'turtle']</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.register_shape">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">register_shape</code><span class="sig-paren">(</span><em>name</em>, <em>shape=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.register_shape" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.addshape">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">addshape</code><span class="sig-paren">(</span><em>name</em>, <em>shape=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.addshape" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>There are three different ways to call this function:</p>
|
|||
|
<ol class="arabic">
|
|||
|
<li><p><em>name</em> is the name of a gif-file and <em>shape</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>: Install the
|
|||
|
corresponding image shape.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">register_shape</span><span class="p">(</span><span class="s2">"turtle.gif"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>Image shapes <em>do not</em> rotate when turning the turtle, so they do not
|
|||
|
display the heading of the turtle!</p>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li><p><em>name</em> is an arbitrary string and <em>shape</em> is a tuple of pairs of
|
|||
|
coordinates: Install the corresponding polygon shape.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">register_shape</span><span class="p">(</span><span class="s2">"triangle"</span><span class="p">,</span> <span class="p">((</span><span class="mi">5</span><span class="p">,</span><span class="o">-</span><span class="mi">3</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="o">-</span><span class="mi">3</span><span class="p">)))</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li><p><em>name</em> is an arbitrary string and shape is a (compound) <a class="reference internal" href="#turtle.Shape" title="turtle.Shape"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shape</span></code></a>
|
|||
|
object: Install the corresponding compound shape.</p></li>
|
|||
|
</ol>
|
|||
|
<p>Add a turtle shape to TurtleScreen’s shapelist. Only thusly registered
|
|||
|
shapes can be used by issuing the command <code class="docutils literal notranslate"><span class="pre">shape(shapename)</span></code>.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.turtles">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">turtles</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.turtles" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the list of turtles on the screen.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">turtle</span> <span class="ow">in</span> <span class="n">screen</span><span class="o">.</span><span class="n">turtles</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">"red"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.window_height">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">window_height</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.window_height" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the height of the turtle window.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">window_height</span><span class="p">()</span>
|
|||
|
<span class="go">480</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.window_width">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">window_width</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.window_width" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Return the width of the turtle window.</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">window_width</span><span class="p">()</span>
|
|||
|
<span class="go">640</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="methods-specific-to-screen-not-inherited-from-turtlescreen">
|
|||
|
<span id="screenspecific"></span><h3>Methods specific to Screen, not inherited from TurtleScreen<a class="headerlink" href="#methods-specific-to-screen-not-inherited-from-turtlescreen" title="Permalink to this headline">¶</a></h3>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.bye">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">bye</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bye" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Shut the turtlegraphics window.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.exitonclick">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">exitonclick</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.exitonclick" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Bind bye() method to mouse clicks on the Screen.</p>
|
|||
|
<p>If the value “using_IDLE” in the configuration dictionary is <code class="docutils literal notranslate"><span class="pre">False</span></code>
|
|||
|
(default value), also enter mainloop. Remark: If IDLE with the <code class="docutils literal notranslate"><span class="pre">-n</span></code> switch
|
|||
|
(no subprocess) is used, this value should be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> in
|
|||
|
<code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code>. In this case IDLE’s own mainloop is active also for the
|
|||
|
client script.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.setup">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">setup</code><span class="sig-paren">(</span><em>width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"]</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setup" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Set the size and position of the main window. Default values of arguments
|
|||
|
are stored in the configuration dictionary and can be changed via a
|
|||
|
<code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> file.</p>
|
|||
|
<dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>width</strong> – if an integer, a size in pixels, if a float, a fraction of the
|
|||
|
screen; default is 50% of screen</p></li>
|
|||
|
<li><p><strong>height</strong> – if an integer, the height in pixels, if a float, a fraction of
|
|||
|
the screen; default is 75% of screen</p></li>
|
|||
|
<li><p><strong>startx</strong> – if positive, starting position in pixels from the left
|
|||
|
edge of the screen, if negative from the right edge, if <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
|||
|
center window horizontally</p></li>
|
|||
|
<li><p><strong>starty</strong> – if positive, starting position in pixels from the top
|
|||
|
edge of the screen, if negative from the bottom edge, if <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
|||
|
center window vertically</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">setup</span> <span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span> <span class="n">startx</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">starty</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span> <span class="c1"># sets window to 200x200 pixels, in upper left of screen</span>
|
|||
|
<span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">setup</span><span class="p">(</span><span class="n">width</span><span class="o">=.</span><span class="mi">75</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">startx</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">starty</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span> <span class="c1"># sets window to 75% of screen by 50% of screen and centers</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.title">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">title</code><span class="sig-paren">(</span><em>titlestring</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.title" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>titlestring</strong> – a string that is shown in the titlebar of the turtle
|
|||
|
graphics window</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Set title of turtle window to <em>titlestring</em>.</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">screen</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s2">"Welcome to the turtle zoo!"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="public-classes">
|
|||
|
<h2>Public classes<a class="headerlink" href="#public-classes" title="Permalink to this headline">¶</a></h2>
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.RawTurtle">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">RawTurtle</code><span class="sig-paren">(</span><em>canvas</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.RawTurtle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dt id="turtle.RawPen">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">RawPen</code><span class="sig-paren">(</span><em>canvas</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.RawPen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>canvas</strong> – a <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code>, a <a class="reference internal" href="#turtle.ScrolledCanvas" title="turtle.ScrolledCanvas"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScrolledCanvas</span></code></a> or a
|
|||
|
<a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a></p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Create a turtle. The turtle has all methods described above as “methods of
|
|||
|
Turtle/RawTurtle”.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.Turtle">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">Turtle</code><a class="headerlink" href="#turtle.Turtle" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Subclass of RawTurtle, has the same interface but draws on a default
|
|||
|
<a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code></a> object created automatically when needed for the first time.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.TurtleScreen">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">TurtleScreen</code><span class="sig-paren">(</span><em>cv</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.TurtleScreen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>cv</strong> – a <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code></p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Provides screen oriented methods like <code class="xref py py-func docutils literal notranslate"><span class="pre">setbg()</span></code> etc. that are described
|
|||
|
above.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.Screen">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">Screen</code><a class="headerlink" href="#turtle.Screen" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Subclass of TurtleScreen, with <a class="reference internal" href="#screenspecific"><span class="std std-ref">four methods added</span></a>.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.ScrolledCanvas">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">ScrolledCanvas</code><span class="sig-paren">(</span><em>master</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ScrolledCanvas" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>master</strong> – some Tkinter widget to contain the ScrolledCanvas, i.e.
|
|||
|
a Tkinter-canvas with scrollbars added</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Used by class Screen, which thus automatically provides a ScrolledCanvas as
|
|||
|
playground for the turtles.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.Shape">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">Shape</code><span class="sig-paren">(</span><em>type_</em>, <em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.Shape" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>type_</strong> – one of the strings “polygon”, “image”, “compound”</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Data structure modeling shapes. The pair <code class="docutils literal notranslate"><span class="pre">(type_,</span> <span class="pre">data)</span></code> must follow this
|
|||
|
specification:</p>
|
|||
|
<table class="docutils align-center">
|
|||
|
<colgroup>
|
|||
|
<col style="width: 16%" />
|
|||
|
<col style="width: 84%" />
|
|||
|
</colgroup>
|
|||
|
<thead>
|
|||
|
<tr class="row-odd"><th class="head"><p><em>type_</em></p></th>
|
|||
|
<th class="head"><p><em>data</em></p></th>
|
|||
|
</tr>
|
|||
|
</thead>
|
|||
|
<tbody>
|
|||
|
<tr class="row-even"><td><p>“polygon”</p></td>
|
|||
|
<td><p>a polygon-tuple, i.e. a tuple of pairs of coordinates</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>“image”</p></td>
|
|||
|
<td><p>an image (in this form only used internally!)</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>“compound”</p></td>
|
|||
|
<td><p><code class="docutils literal notranslate"><span class="pre">None</span></code> (a compound shape has to be constructed using the
|
|||
|
<a class="reference internal" href="#turtle.Shape.addcomponent" title="turtle.Shape.addcomponent"><code class="xref py py-meth docutils literal notranslate"><span class="pre">addcomponent()</span></code></a> method)</p></td>
|
|||
|
</tr>
|
|||
|
</tbody>
|
|||
|
</table>
|
|||
|
<dl class="method">
|
|||
|
<dt id="turtle.Shape.addcomponent">
|
|||
|
<code class="descname">addcomponent</code><span class="sig-paren">(</span><em>poly</em>, <em>fill</em>, <em>outline=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.Shape.addcomponent" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><ul class="simple">
|
|||
|
<li><p><strong>poly</strong> – a polygon, i.e. a tuple of pairs of numbers</p></li>
|
|||
|
<li><p><strong>fill</strong> – a color the <em>poly</em> will be filled with</p></li>
|
|||
|
<li><p><strong>outline</strong> – a color for the poly’s outline (if given)</p></li>
|
|||
|
</ul>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Example:</p>
|
|||
|
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">poly</span> <span class="o">=</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">),(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">),(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">))</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">Shape</span><span class="p">(</span><span class="s2">"compound"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">addcomponent</span><span class="p">(</span><span class="n">poly</span><span class="p">,</span> <span class="s2">"red"</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="c1"># ... add more components and then use register_shape()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>See <a class="reference internal" href="#compoundshapes"><span class="std std-ref">Compound shapes</span></a>.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="class">
|
|||
|
<dt id="turtle.Vec2D">
|
|||
|
<em class="property">class </em><code class="descclassname">turtle.</code><code class="descname">Vec2D</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.Vec2D" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>A two-dimensional vector class, used as a helper class for implementing
|
|||
|
turtle graphics. May be useful for turtle graphics programs too. Derived
|
|||
|
from tuple, so a vector is a tuple!</p>
|
|||
|
<p>Provides (for <em>a</em>, <em>b</em> vectors, <em>k</em> number):</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></code> vector addition</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">b</span></code> vector subtraction</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*</span> <span class="pre">b</span></code> inner product</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">k</span> <span class="pre">*</span> <span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*</span> <span class="pre">k</span></code> multiplication with scalar</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">abs(a)</span></code> absolute value of a</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">a.rotate(angle)</span></code> rotation</p></li>
|
|||
|
</ul>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="help-and-configuration">
|
|||
|
<h2>Help and configuration<a class="headerlink" href="#help-and-configuration" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="how-to-use-help">
|
|||
|
<h3>How to use help<a class="headerlink" href="#how-to-use-help" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The public methods of the Screen and Turtle classes are documented extensively
|
|||
|
via docstrings. So these can be used as online-help via the Python help
|
|||
|
facilities:</p>
|
|||
|
<ul>
|
|||
|
<li><p>When using IDLE, tooltips show the signatures and first lines of the
|
|||
|
docstrings of typed in function-/method calls.</p></li>
|
|||
|
<li><p>Calling <a class="reference internal" href="functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> on methods or functions displays the docstrings:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">help</span><span class="p">(</span><span class="n">Screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">)</span>
|
|||
|
<span class="go">Help on method bgcolor in module turtle:</span>
|
|||
|
|
|||
|
<span class="go">bgcolor(self, *args) unbound turtle.Screen method</span>
|
|||
|
<span class="go"> Set or return backgroundcolor of the TurtleScreen.</span>
|
|||
|
|
|||
|
<span class="go"> Arguments (if given): a color string or three numbers</span>
|
|||
|
<span class="go"> in the range 0..colormode or a 3-tuple of such numbers.</span>
|
|||
|
|
|||
|
|
|||
|
<span class="go"> >>> screen.bgcolor("orange")</span>
|
|||
|
<span class="go"> >>> screen.bgcolor()</span>
|
|||
|
<span class="go"> "orange"</span>
|
|||
|
<span class="go"> >>> screen.bgcolor(0.5,0,0.5)</span>
|
|||
|
<span class="go"> >>> screen.bgcolor()</span>
|
|||
|
<span class="go"> "#800080"</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">help</span><span class="p">(</span><span class="n">Turtle</span><span class="o">.</span><span class="n">penup</span><span class="p">)</span>
|
|||
|
<span class="go">Help on method penup in module turtle:</span>
|
|||
|
|
|||
|
<span class="go">penup(self) unbound turtle.Turtle method</span>
|
|||
|
<span class="go"> Pull the pen up -- no drawing when moving.</span>
|
|||
|
|
|||
|
<span class="go"> Aliases: penup | pu | up</span>
|
|||
|
|
|||
|
<span class="go"> No argument</span>
|
|||
|
|
|||
|
<span class="go"> >>> turtle.penup()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li><p>The docstrings of the functions which are derived from methods have a modified
|
|||
|
form:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">help</span><span class="p">(</span><span class="n">bgcolor</span><span class="p">)</span>
|
|||
|
<span class="go">Help on function bgcolor in module turtle:</span>
|
|||
|
|
|||
|
<span class="go">bgcolor(*args)</span>
|
|||
|
<span class="go"> Set or return backgroundcolor of the TurtleScreen.</span>
|
|||
|
|
|||
|
<span class="go"> Arguments (if given): a color string or three numbers</span>
|
|||
|
<span class="go"> in the range 0..colormode or a 3-tuple of such numbers.</span>
|
|||
|
|
|||
|
<span class="go"> Example::</span>
|
|||
|
|
|||
|
<span class="go"> >>> bgcolor("orange")</span>
|
|||
|
<span class="go"> >>> bgcolor()</span>
|
|||
|
<span class="go"> "orange"</span>
|
|||
|
<span class="go"> >>> bgcolor(0.5,0,0.5)</span>
|
|||
|
<span class="go"> >>> bgcolor()</span>
|
|||
|
<span class="go"> "#800080"</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">help</span><span class="p">(</span><span class="n">penup</span><span class="p">)</span>
|
|||
|
<span class="go">Help on function penup in module turtle:</span>
|
|||
|
|
|||
|
<span class="go">penup()</span>
|
|||
|
<span class="go"> Pull the pen up -- no drawing when moving.</span>
|
|||
|
|
|||
|
<span class="go"> Aliases: penup | pu | up</span>
|
|||
|
|
|||
|
<span class="go"> No argument</span>
|
|||
|
|
|||
|
<span class="go"> Example:</span>
|
|||
|
<span class="go"> >>> penup()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
<p>These modified docstrings are created automatically together with the function
|
|||
|
definitions that are derived from the methods at import time.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="translation-of-docstrings-into-different-languages">
|
|||
|
<h3>Translation of docstrings into different languages<a class="headerlink" href="#translation-of-docstrings-into-different-languages" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>There is a utility to create a dictionary the keys of which are the method names
|
|||
|
and the values of which are the docstrings of the public methods of the classes
|
|||
|
Screen and Turtle.</p>
|
|||
|
<dl class="function">
|
|||
|
<dt id="turtle.write_docstringdict">
|
|||
|
<code class="descclassname">turtle.</code><code class="descname">write_docstringdict</code><span class="sig-paren">(</span><em>filename="turtle_docstringdict"</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.write_docstringdict" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><dl class="field-list simple">
|
|||
|
<dt class="field-odd">Parameters</dt>
|
|||
|
<dd class="field-odd"><p><strong>filename</strong> – a string, used as filename</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>Create and write docstring-dictionary to a Python script with the given
|
|||
|
filename. This function has to be called explicitly (it is not used by the
|
|||
|
turtle graphics classes). The docstring dictionary will be written to the
|
|||
|
Python script <code class="file docutils literal notranslate"><em><span class="pre">filename</span></em><span class="pre">.py</span></code>. It is intended to serve as a template
|
|||
|
for translation of the docstrings into different languages.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<p>If you (or your students) want to use <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> with online help in your
|
|||
|
native language, you have to translate the docstrings and save the resulting
|
|||
|
file as e.g. <code class="file docutils literal notranslate"><span class="pre">turtle_docstringdict_german.py</span></code>.</p>
|
|||
|
<p>If you have an appropriate entry in your <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> file this dictionary
|
|||
|
will be read in at import time and will replace the original English docstrings.</p>
|
|||
|
<p>At the time of this writing there are docstring dictionaries in German and in
|
|||
|
Italian. (Requests please to <a class="reference external" href="mailto:glingl%40aon.at">glingl<span>@</span>aon<span>.</span>at</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="how-to-configure-screen-and-turtles">
|
|||
|
<h3>How to configure Screen and Turtles<a class="headerlink" href="#how-to-configure-screen-and-turtles" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The built-in default configuration mimics the appearance and behaviour of the
|
|||
|
old turtle module in order to retain best possible compatibility with it.</p>
|
|||
|
<p>If you want to use a different configuration which better reflects the features
|
|||
|
of this module or which better fits to your needs, e.g. for use in a classroom,
|
|||
|
you can prepare a configuration file <code class="docutils literal notranslate"><span class="pre">turtle.cfg</span></code> which will be read at import
|
|||
|
time and modify the configuration according to its settings.</p>
|
|||
|
<p>The built in configuration would correspond to the following turtle.cfg:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">width</span> <span class="o">=</span> <span class="mf">0.5</span>
|
|||
|
<span class="n">height</span> <span class="o">=</span> <span class="mf">0.75</span>
|
|||
|
<span class="n">leftright</span> <span class="o">=</span> <span class="kc">None</span>
|
|||
|
<span class="n">topbottom</span> <span class="o">=</span> <span class="kc">None</span>
|
|||
|
<span class="n">canvwidth</span> <span class="o">=</span> <span class="mi">400</span>
|
|||
|
<span class="n">canvheight</span> <span class="o">=</span> <span class="mi">300</span>
|
|||
|
<span class="n">mode</span> <span class="o">=</span> <span class="n">standard</span>
|
|||
|
<span class="n">colormode</span> <span class="o">=</span> <span class="mf">1.0</span>
|
|||
|
<span class="n">delay</span> <span class="o">=</span> <span class="mi">10</span>
|
|||
|
<span class="n">undobuffersize</span> <span class="o">=</span> <span class="mi">1000</span>
|
|||
|
<span class="n">shape</span> <span class="o">=</span> <span class="n">classic</span>
|
|||
|
<span class="n">pencolor</span> <span class="o">=</span> <span class="n">black</span>
|
|||
|
<span class="n">fillcolor</span> <span class="o">=</span> <span class="n">black</span>
|
|||
|
<span class="n">resizemode</span> <span class="o">=</span> <span class="n">noresize</span>
|
|||
|
<span class="n">visible</span> <span class="o">=</span> <span class="kc">True</span>
|
|||
|
<span class="n">language</span> <span class="o">=</span> <span class="n">english</span>
|
|||
|
<span class="n">exampleturtle</span> <span class="o">=</span> <span class="n">turtle</span>
|
|||
|
<span class="n">examplescreen</span> <span class="o">=</span> <span class="n">screen</span>
|
|||
|
<span class="n">title</span> <span class="o">=</span> <span class="n">Python</span> <span class="n">Turtle</span> <span class="n">Graphics</span>
|
|||
|
<span class="n">using_IDLE</span> <span class="o">=</span> <span class="kc">False</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Short explanation of selected entries:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The first four lines correspond to the arguments of the <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.setup()</span></code>
|
|||
|
method.</p></li>
|
|||
|
<li><p>Line 5 and 6 correspond to the arguments of the method
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.screensize()</span></code>.</p></li>
|
|||
|
<li><p><em>shape</em> can be any of the built-in shapes, e.g: arrow, turtle, etc. For more
|
|||
|
info try <code class="docutils literal notranslate"><span class="pre">help(shape)</span></code>.</p></li>
|
|||
|
<li><p>If you want to use no fillcolor (i.e. make the turtle transparent), you have
|
|||
|
to write <code class="docutils literal notranslate"><span class="pre">fillcolor</span> <span class="pre">=</span> <span class="pre">""</span></code> (but all nonempty strings must not have quotes in
|
|||
|
the cfg-file).</p></li>
|
|||
|
<li><p>If you want to reflect the turtle its state, you have to use <code class="docutils literal notranslate"><span class="pre">resizemode</span> <span class="pre">=</span>
|
|||
|
<span class="pre">auto</span></code>.</p></li>
|
|||
|
<li><p>If you set e.g. <code class="docutils literal notranslate"><span class="pre">language</span> <span class="pre">=</span> <span class="pre">italian</span></code> the docstringdict
|
|||
|
<code class="file docutils literal notranslate"><span class="pre">turtle_docstringdict_italian.py</span></code> will be loaded at import time (if
|
|||
|
present on the import path, e.g. in the same directory as <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a>.</p></li>
|
|||
|
<li><p>The entries <em>exampleturtle</em> and <em>examplescreen</em> define the names of these
|
|||
|
objects as they occur in the docstrings. The transformation of
|
|||
|
method-docstrings to function-docstrings will delete these names from the
|
|||
|
docstrings.</p></li>
|
|||
|
<li><p><em>using_IDLE</em>: Set this to <code class="docutils literal notranslate"><span class="pre">True</span></code> if you regularly work with IDLE and its -n
|
|||
|
switch (“no subprocess”). This will prevent <a class="reference internal" href="#turtle.exitonclick" title="turtle.exitonclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">exitonclick()</span></code></a> to enter the
|
|||
|
mainloop.</p></li>
|
|||
|
</ul>
|
|||
|
<p>There can be a <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> file in the directory where <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> is
|
|||
|
stored and an additional one in the current working directory. The latter will
|
|||
|
override the settings of the first one.</p>
|
|||
|
<p>The <code class="file docutils literal notranslate"><span class="pre">Lib/turtledemo</span></code> directory contains a <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> file. You can
|
|||
|
study it as an example and see its effects when running the demos (preferably
|
|||
|
not from within the demo-viewer).</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="module-turtledemo">
|
|||
|
<span id="turtledemo-demo-scripts"></span><h2><a class="reference internal" href="#module-turtledemo" title="turtledemo: A viewer for example turtle scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code></a> — Demo scripts<a class="headerlink" href="#module-turtledemo" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>The <a class="reference internal" href="#module-turtledemo" title="turtledemo: A viewer for example turtle scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code></a> package includes a set of demo scripts. These
|
|||
|
scripts can be run and viewed using the supplied demo viewer as follows:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">turtledemo</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Alternatively, you can run the demo scripts individually. For example,</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">turtledemo</span><span class="o">.</span><span class="n">bytedesign</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>The <a class="reference internal" href="#module-turtledemo" title="turtledemo: A viewer for example turtle scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code></a> package directory contains:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>A demo viewer <code class="file docutils literal notranslate"><span class="pre">__main__.py</span></code> which can be used to view the sourcecode
|
|||
|
of the scripts and run them at the same time.</p></li>
|
|||
|
<li><p>Multiple scripts demonstrating different features of the <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a>
|
|||
|
module. Examples can be accessed via the Examples menu. They can also
|
|||
|
be run standalone.</p></li>
|
|||
|
<li><p>A <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> file which serves as an example of how to write
|
|||
|
and use such files.</p></li>
|
|||
|
</ul>
|
|||
|
<p>The demo scripts are:</p>
|
|||
|
<table class="docutils align-center">
|
|||
|
<colgroup>
|
|||
|
<col style="width: 23%" />
|
|||
|
<col style="width: 43%" />
|
|||
|
<col style="width: 33%" />
|
|||
|
</colgroup>
|
|||
|
<thead>
|
|||
|
<tr class="row-odd"><th class="head"><p>Name</p></th>
|
|||
|
<th class="head"><p>Description</p></th>
|
|||
|
<th class="head"><p>Features</p></th>
|
|||
|
</tr>
|
|||
|
</thead>
|
|||
|
<tbody>
|
|||
|
<tr class="row-even"><td><p>bytedesign</p></td>
|
|||
|
<td><p>complex classical
|
|||
|
turtle graphics pattern</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">tracer()</span></code>, delay,
|
|||
|
<code class="xref py py-func docutils literal notranslate"><span class="pre">update()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>chaos</p></td>
|
|||
|
<td><p>graphs Verhulst dynamics,
|
|||
|
shows that computer’s
|
|||
|
computations can generate
|
|||
|
results sometimes against the
|
|||
|
common sense expectations</p></td>
|
|||
|
<td><p>world coordinates</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>clock</p></td>
|
|||
|
<td><p>analog clock showing time
|
|||
|
of your computer</p></td>
|
|||
|
<td><p>turtles as clock’s
|
|||
|
hands, ontimer</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>colormixer</p></td>
|
|||
|
<td><p>experiment with r, g, b</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">ondrag()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>forest</p></td>
|
|||
|
<td><p>3 breadth-first trees</p></td>
|
|||
|
<td><p>randomization</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>fractalcurves</p></td>
|
|||
|
<td><p>Hilbert & Koch curves</p></td>
|
|||
|
<td><p>recursion</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>lindenmayer</p></td>
|
|||
|
<td><p>ethnomathematics
|
|||
|
(indian kolams)</p></td>
|
|||
|
<td><p>L-System</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>minimal_hanoi</p></td>
|
|||
|
<td><p>Towers of Hanoi</p></td>
|
|||
|
<td><p>Rectangular Turtles
|
|||
|
as Hanoi discs
|
|||
|
(shape, shapesize)</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>nim</p></td>
|
|||
|
<td><p>play the classical nim game
|
|||
|
with three heaps of sticks
|
|||
|
against the computer.</p></td>
|
|||
|
<td><p>turtles as nimsticks,
|
|||
|
event driven (mouse,
|
|||
|
keyboard)</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>paint</p></td>
|
|||
|
<td><p>super minimalistic
|
|||
|
drawing program</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">onclick()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>peace</p></td>
|
|||
|
<td><p>elementary</p></td>
|
|||
|
<td><p>turtle: appearance
|
|||
|
and animation</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>penrose</p></td>
|
|||
|
<td><p>aperiodic tiling with
|
|||
|
kites and darts</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">stamp()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>planet_and_moon</p></td>
|
|||
|
<td><p>simulation of
|
|||
|
gravitational system</p></td>
|
|||
|
<td><p>compound shapes,
|
|||
|
<code class="xref py py-class docutils literal notranslate"><span class="pre">Vec2D</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>round_dance</p></td>
|
|||
|
<td><p>dancing turtles rotating
|
|||
|
pairwise in opposite
|
|||
|
direction</p></td>
|
|||
|
<td><p>compound shapes, clone
|
|||
|
shapesize, tilt,
|
|||
|
get_shapepoly, update</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>sorting_animate</p></td>
|
|||
|
<td><p>visual demonstration of
|
|||
|
different sorting methods</p></td>
|
|||
|
<td><p>simple alignment,
|
|||
|
randomization</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>tree</p></td>
|
|||
|
<td><p>a (graphical) breadth
|
|||
|
first tree (using generators)</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">clone()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>two_canvases</p></td>
|
|||
|
<td><p>simple design</p></td>
|
|||
|
<td><p>turtles on two
|
|||
|
canvases</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>wikipedia</p></td>
|
|||
|
<td><p>a pattern from the wikipedia
|
|||
|
article on turtle graphics</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">clone()</span></code>,
|
|||
|
<code class="xref py py-func docutils literal notranslate"><span class="pre">undo()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td><p>yinyang</p></td>
|
|||
|
<td><p>another elementary example</p></td>
|
|||
|
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">circle()</span></code></p></td>
|
|||
|
</tr>
|
|||
|
</tbody>
|
|||
|
</table>
|
|||
|
<p>Have fun!</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="changes-since-python-2-6">
|
|||
|
<h2>Changes since Python 2.6<a class="headerlink" href="#changes-since-python-2-6" title="Permalink to this headline">¶</a></h2>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.tracer()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.window_width()</span></code> and
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.window_height()</span></code> have been eliminated.
|
|||
|
Methods with these names and functionality are now available only
|
|||
|
as methods of <code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code>. The functions derived from these remain
|
|||
|
available. (In fact already in Python 2.6 these methods were merely
|
|||
|
duplications of the corresponding
|
|||
|
<code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code>/<code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code>-methods.)</p></li>
|
|||
|
<li><p>The method <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.fill()</span></code> has been eliminated.
|
|||
|
The behaviour of <code class="xref py py-meth docutils literal notranslate"><span class="pre">begin_fill()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">end_fill()</span></code>
|
|||
|
have changed slightly: now every filling-process must be completed with an
|
|||
|
<code class="docutils literal notranslate"><span class="pre">end_fill()</span></code> call.</p></li>
|
|||
|
<li><p>A method <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.filling()</span></code> has been added. It returns a boolean
|
|||
|
value: <code class="docutils literal notranslate"><span class="pre">True</span></code> if a filling process is under way, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.
|
|||
|
This behaviour corresponds to a <code class="docutils literal notranslate"><span class="pre">fill()</span></code> call without arguments in
|
|||
|
Python 2.6.</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="section" id="changes-since-python-3-0">
|
|||
|
<h2>Changes since Python 3.0<a class="headerlink" href="#changes-since-python-3-0" title="Permalink to this headline">¶</a></h2>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.shearfactor()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.shapetransform()</span></code> and
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.get_shapepoly()</span></code> have been added. Thus the full range of
|
|||
|
regular linear transforms is now available for transforming turtle shapes.
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.tiltangle()</span></code> has been enhanced in functionality: it now can
|
|||
|
be used to get or set the tiltangle. <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.settiltangle()</span></code> has been
|
|||
|
deprecated.</p></li>
|
|||
|
<li><p>The method <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.onkeypress()</span></code> has been added as a complement to
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.onkey()</span></code> which in fact binds actions to the keyrelease event.
|
|||
|
Accordingly the latter has got an alias: <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.onkeyrelease()</span></code>.</p></li>
|
|||
|
<li><p>The method <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.mainloop()</span></code> has been added. So when working only
|
|||
|
with Screen and Turtle objects one must not additionally import
|
|||
|
<code class="xref py py-func docutils literal notranslate"><span class="pre">mainloop()</span></code> anymore.</p></li>
|
|||
|
<li><p>Two input methods has been added <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.textinput()</span></code> and
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.numinput()</span></code>. These popup input dialogs and return
|
|||
|
strings and numbers respectively.</p></li>
|
|||
|
<li><p>Two example scripts <code class="file docutils literal notranslate"><span class="pre">tdemo_nim.py</span></code> and <code class="file docutils literal notranslate"><span class="pre">tdemo_round_dance.py</span></code>
|
|||
|
have been added to the <code class="file docutils literal notranslate"><span class="pre">Lib/turtledemo</span></code> directory.</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|||
|
<div class="sphinxsidebarwrapper">
|
|||
|
<h3><a href="../contents.html">Table of Contents</a></h3>
|
|||
|
<ul>
|
|||
|
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code> — Turtle graphics</a><ul>
|
|||
|
<li><a class="reference internal" href="#introduction">Introduction</a></li>
|
|||
|
<li><a class="reference internal" href="#overview-of-available-turtle-and-screen-methods">Overview of available Turtle and Screen methods</a><ul>
|
|||
|
<li><a class="reference internal" href="#turtle-methods">Turtle methods</a></li>
|
|||
|
<li><a class="reference internal" href="#methods-of-turtlescreen-screen">Methods of TurtleScreen/Screen</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#methods-of-rawturtle-turtle-and-corresponding-functions">Methods of RawTurtle/Turtle and corresponding functions</a><ul>
|
|||
|
<li><a class="reference internal" href="#turtle-motion">Turtle motion</a></li>
|
|||
|
<li><a class="reference internal" href="#tell-turtle-s-state">Tell Turtle’s state</a></li>
|
|||
|
<li><a class="reference internal" href="#settings-for-measurement">Settings for measurement</a></li>
|
|||
|
<li><a class="reference internal" href="#pen-control">Pen control</a><ul>
|
|||
|
<li><a class="reference internal" href="#drawing-state">Drawing state</a></li>
|
|||
|
<li><a class="reference internal" href="#color-control">Color control</a></li>
|
|||
|
<li><a class="reference internal" href="#filling">Filling</a></li>
|
|||
|
<li><a class="reference internal" href="#more-drawing-control">More drawing control</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#turtle-state">Turtle state</a><ul>
|
|||
|
<li><a class="reference internal" href="#visibility">Visibility</a></li>
|
|||
|
<li><a class="reference internal" href="#appearance">Appearance</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#using-events">Using events</a></li>
|
|||
|
<li><a class="reference internal" href="#special-turtle-methods">Special Turtle methods</a></li>
|
|||
|
<li><a class="reference internal" href="#compound-shapes">Compound shapes</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#methods-of-turtlescreen-screen-and-corresponding-functions">Methods of TurtleScreen/Screen and corresponding functions</a><ul>
|
|||
|
<li><a class="reference internal" href="#window-control">Window control</a></li>
|
|||
|
<li><a class="reference internal" href="#animation-control">Animation control</a></li>
|
|||
|
<li><a class="reference internal" href="#using-screen-events">Using screen events</a></li>
|
|||
|
<li><a class="reference internal" href="#input-methods">Input methods</a></li>
|
|||
|
<li><a class="reference internal" href="#settings-and-special-methods">Settings and special methods</a></li>
|
|||
|
<li><a class="reference internal" href="#methods-specific-to-screen-not-inherited-from-turtlescreen">Methods specific to Screen, not inherited from TurtleScreen</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#public-classes">Public classes</a></li>
|
|||
|
<li><a class="reference internal" href="#help-and-configuration">Help and configuration</a><ul>
|
|||
|
<li><a class="reference internal" href="#how-to-use-help">How to use help</a></li>
|
|||
|
<li><a class="reference internal" href="#translation-of-docstrings-into-different-languages">Translation of docstrings into different languages</a></li>
|
|||
|
<li><a class="reference internal" href="#how-to-configure-screen-and-turtles">How to configure Screen and Turtles</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#module-turtledemo"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code> — Demo scripts</a></li>
|
|||
|
<li><a class="reference internal" href="#changes-since-python-2-6">Changes since Python 2.6</a></li>
|
|||
|
<li><a class="reference internal" href="#changes-since-python-3-0">Changes since Python 3.0</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<h4>Previous topic</h4>
|
|||
|
<p class="topless"><a href="frameworks.html"
|
|||
|
title="previous chapter">Program Frameworks</a></p>
|
|||
|
<h4>Next topic</h4>
|
|||
|
<p class="topless"><a href="cmd.html"
|
|||
|
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmd</span></code> — Support for line-oriented command interpreters</a></p>
|
|||
|
<div role="note" aria-label="source link">
|
|||
|
<h3>This Page</h3>
|
|||
|
<ul class="this-page-menu">
|
|||
|
<li><a href="../bugs.html">Report a Bug</a></li>
|
|||
|
<li>
|
|||
|
<a href="https://github.com/python/cpython/blob/3.7/Doc/library/turtle.rst"
|
|||
|
rel="nofollow">Show Source
|
|||
|
</a>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="clearer"></div>
|
|||
|
</div>
|
|||
|
<div class="related" role="navigation" aria-label="related navigation">
|
|||
|
<h3>Navigation</h3>
|
|||
|
<ul>
|
|||
|
<li class="right" style="margin-right: 10px">
|
|||
|
<a href="../genindex.html" title="General Index"
|
|||
|
>index</a></li>
|
|||
|
<li class="right" >
|
|||
|
<a href="../py-modindex.html" title="Python Module Index"
|
|||
|
>modules</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="cmd.html" title="cmd — Support for line-oriented command interpreters"
|
|||
|
>next</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="frameworks.html" title="Program Frameworks"
|
|||
|
>previous</a> |</li>
|
|||
|
<li><img src="../_static/py.png" alt=""
|
|||
|
style="vertical-align: middle; margin-top: -1px"/></li>
|
|||
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|||
|
<li>
|
|||
|
<span class="language_switcher_placeholder">en</span>
|
|||
|
<span class="version_switcher_placeholder">3.7.4</span>
|
|||
|
<a href="../index.html">Documentation </a> »
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
|||
|
<li class="nav-item nav-item-2"><a href="frameworks.html" >Program Frameworks</a> »</li>
|
|||
|
<li class="right">
|
|||
|
|
|||
|
|
|||
|
<div class="inline-search" style="display: none" role="search">
|
|||
|
<form class="inline-search" action="../search.html" method="get">
|
|||
|
<input placeholder="Quick search" type="text" name="q" />
|
|||
|
<input type="submit" value="Go" />
|
|||
|
<input type="hidden" name="check_keywords" value="yes" />
|
|||
|
<input type="hidden" name="area" value="default" />
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
<script type="text/javascript">$('.inline-search').show(0);</script>
|
|||
|
|
|
|||
|
</li>
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="footer">
|
|||
|
© <a href="../copyright.html">Copyright</a> 2001-2019, Python Software Foundation.
|
|||
|
<br />
|
|||
|
The Python Software Foundation is a non-profit corporation.
|
|||
|
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
|||
|
<br />
|
|||
|
Last updated on Jul 13, 2019.
|
|||
|
<a href="../bugs.html">Found a bug</a>?
|
|||
|
<br />
|
|||
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
|||
|
</div>
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|