Make turtle.pensize smarter
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong turtle.py, tại phần triển khai pensize, và so sánh cách xử lý yêu cầu đã được tài liệu hóa về độ rộng dương với lỗi forward được báo cáo. Xem lại cuộc thảo luận được liên kết và gh-135268 trước khi tiếp tục; hoàn tất có nghĩa là các độ rộng không dương không hợp lệ được xử lý tại thời điểm pensize thay vì gây lỗi trong một thao tác vẽ sau đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- computer-graphics
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100