Reputation: 1561
I am trying to draw a vertical line using python-pptx module but haven't been able.
The below helps me draw a horizontal line but I am not sure how to get a vertical line in the slide
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[1])
line1 = slide.shapes.add_shape(MSO_SHAPE.LINE_INVERSE, Inches(6), Inches(6), Inches(1), Inches(2))
prs.save('sample.pptx')
Upvotes: 2
Views: 1277
Reputation: 29021
Use shapes.add_connector()
:
https://python-pptx.readthedocs.io/en/latest/api/shapes.html#pptx.shapes.shapetree.SlideShapes.add_connector
Its signature is:
add_connector(connector_type, begin_x, begin_y, end_x, end_y)
and it's used like this:
from pptx.enum.shapes import MSO_CONNECTOR
from pptx.util import Cm
line = slide.shapes.add_connector(
MSO_CONNECTOR.STRAIGHT, Cm(2), Cm(2), Cm(10), Cm(10)
)
The first two length values specify the starting point and the remaining two specify the end point.
Upvotes: 2