簡體   English   中英

繪制龜圖形

[英]Drawing in turtle graphics

我正在嘗試將文件解析為列表,然后使用烏龜圖形在列表中繪制形狀。 我設法解析該文件並將其成功返回為列表,但是,當我嘗試使用烏龜圖形在文件中繪制形狀時,出現錯誤。 這是代碼:

list_of_shapes = parser.parse(local_file_name) # this will parse the file into a list
drawer = Turtle_Draw_Shape_Controller()
drawer.draw_shapes(list_of_shapes)

一旦我嘗試使用烏龜圖形繪制圖片,就會收到以下錯誤消息:

Traceback (most recent call last):
  File "/Volumes/shapes.py, line 206, in <module>
    drawer.draw_shapes(list_of_shapes)
  File "/Volumes/shapes.py", line 184, in draw_shapes
    shape_type = shape.get_shape_type()
AttributeError: 'tuple' object has no attribute 'get_shape_type'

您的形狀解析器功能正在將元組添加到shapes_list ,例如:

shapes_list.append(("c",cir))

然后,您嘗試將這些形狀直接用作形狀。 更改分析器以僅附加形狀本身: shapes_list.append(cir) ,或者在將其在draw方法中使用之前,從元組中解壓縮形狀對象:

for shape_type, shape in shapes:

如果每個形狀對象已經具有get_shape_type方法,我不確定為什么要從外部附加類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM