Skip to content

gh-136722: add TurtleGraphicsError documentation #136838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Doc/library/turtle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,82 @@ Public classes
* ``a.rotate(angle)`` rotation


Exceptions
----------


.. exception:: TurtleGraphicsError

Exception raised when a turtle graphics operation fails.

This exception is raised in various error conditions, such as:

* Invalid color specifications (e.g., color values out of range)
* Invalid shape types or names
* Invalid turtle graphics modes
* Invalid canvas arguments
* Other turtle graphics configuration errors

Examples:

**Invalid color specifications:**

.. doctest::
:skipif: _tkinter is None

>>> screen.colormode(1.0)
>>> turtle.pencolor(240, 160, 80)
Traceback (most recent call last):
...
TurtleGraphicsError: bad color sequence: (240, 160, 80)

>>> turtle.pencolor("invalid_color_name")
Traceback (most recent call last):
...
TurtleGraphicsError: bad color string: invalid_color_name

**Invalid shape types:**

.. doctest::
:skipif: _tkinter is None

>>> from turtle import Shape
>>> s = Shape("invalid_type", None)
Traceback (most recent call last):
...
TurtleGraphicsError: There is no shape type invalid_type

**Invalid turtle graphics modes:**

.. doctest::
:skipif: _tkinter is None

>>> screen.mode("invalid_mode")
Traceback (most recent call last):
...
TurtleGraphicsError: No turtle-graphics-mode invalid_mode

**Invalid shape names:**

.. doctest::
:skipif: _tkinter is None

>>> turtle.shape("nonexistent_shape")
Traceback (most recent call last):
...
TurtleGraphicsError: There is no shape named nonexistent_shape

**Invalid shape parameters:**

.. doctest::
:skipif: _tkinter is None

>>> turtle.shapesize(stretch_wid=0, stretch_len=1)
Traceback (most recent call last):
...
TurtleGraphicsError: stretch_wid/stretch_len must not be zero


.. _turtle-explanation:

Explanation
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy