2

I'm using python-pptx library and connecting shapes in a slide. I'm trying to create an arrow Connector shape like this:

Expected

But I couldn't find any attribute to change the straight line to an arrow line. I've already read in the documentation about dash_style, but this doesn't change the format only the style.

David Buck
  • 3,752
  • 35
  • 31
  • 35
cilopez
  • 75
  • 2
  • 9
  • Have you read through all of [these](https://python-pptx.readthedocs.io/en/latest/search.html?q=arrow&check_keywords=yes&area=default)? – Nearoo Nov 10 '19 at 21:45
  • Yes, the closest thing is MsoConnectorType, but there is no option for arrow connector type. :( – cilopez Nov 10 '19 at 21:56

1 Answers1

2

I have found the solution here.

from pptx.oxml import parse_xml
from pptx.enum.shapes import MSO_CONNECTOR_TYPE

connector = prs.slides[0].shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, Cm(start_left), Cm(start_top), Cm(end_left), Cm(end_top))
line_elem = connector.line._get_or_add_ln()
line_elem.append(parse_xml("""
        <a:headEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
 """))
 
# or

line_elem = connector.line._get_or_add_ln()
line_elem.append(parse_xml("""
        <a:tailEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
 """))

# change line color and width
connector.line.fill.solid()
connector.line.fill.fore_color.rgb = RGBColor(0, 0, 0)
connector.line.width = Pt(2.5)