Make turtle.pensize smarter
未關閉
還沒有人認領這個 Issue。
stdlib
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 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