简体   繁体   中英

Drawing in turtle graphics

I am trying to parse a file into a list and then use turtle graphics to draw the shapes in the list. I managed to parse the file and return it as a list successfully, however, when I try to use turtle graphics to draw the shapes in the file I get an error. Here is the code:

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)

Once I try to use turtle graphics to draw the pictures, I get this error:

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'

Your shape parser function is adding tuples to the shapes_list , eg:

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

You're then trying to use those directly as shapes. Either change the parser to just append the shape itself: shapes_list.append(cir) , or unpack the shape object from the tuple before using it in your draw method:

for shape_type, shape in shapes:

I'm not sure why you'd attach the types externally to begin with if each shape object already has a get_shape_type method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM