Make turtle.pensize smarter
未关闭
还没有人认领这个 Issue。
stdlib
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 turtle.py 中 pensize 的实现开始,将其对文档所述正宽度要求的处理方式与报告的 forward 失败进行比较。在继续之前,查看链接的讨论和 gh-135268;完成意味着无效的非正宽度会在 pensize 时处理,而不是在之后的绘制操作中失败。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- computer-graphics
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100