[英]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.