Make turtle.pensize smarter
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
The turtle.pensize doc says:
turtle.pensize(width=None)
Parameters:
width – a positive number
However, if you put a non-positive number, the function will accept it without any error or warning.
Afterwards, a draw action (like forward) will raise an exception. See below.
>>> import turtle
>>> turtle.pensize(-1)
>>> turtle.forward(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 8, in forward
File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 1636, in forward
self._go(distance)
File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 1597, in _go
self._goto(ende)
File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 3248, in _goto
screen._drawline(self.drawingLineItem,
File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 543, in _drawline
self.cv.itemconfigure(lineitem, width=width)
File "<string>", line 1, in itemconfigure
File "/home/adorilson/anaconda3/lib/python3.12/tkinter/__init__.py", line 2988, in itemconfigure
return self._configure(('itemconfigure', tagOrId), cnf, kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adorilson/anaconda3/lib/python3.12/tkinter/__init__.py", line 1712, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: bad screen distance "-1"
>>>
My suggestion is pensize (and probably others) raises a TurtleGraphicsError if the width argument is less than 1.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
https://discuss.python.org/t/improving-the-turtle-library/61840/18
Linked PRs
- gh-135268
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in turtle.py at the pensize implementation and compare its handling of the documented positive width requirement with the reported forward failure. Review the linked discussion and gh-135268 before proceeding; done means invalid non-positive widths are handled at pensize time rather than failing during a later draw action.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100