Search code examples
pythonpowerpointpython-pptx

AttributeError: 'SlideShapes' object has no attribute 'text_frame'


I am using python-pptx library for editing powerpoint presentation in python. But on running the below script:

from pptx import Presentation
prs = Presentation('path/to/presentation.pptx')
slide = prs.slides[0]
shape = slide.shapes
shape.text_frame.text = "Introduction"

the error that arises is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[18], line 3
      1 slide = prs.slides[0]
      2 shape = slide.shapes
----> 3 shape.text_frame.text = "Introduction"

AttributeError: 'SlideShapes' object has no attribute 'text_frame'

Here I am using python-pptx==0.6.21. Is there any method for the same?


Solution

  • Shouldn't that be

    shape = slide.shapes[0]
    

    as it's the first shape you want.