AttributeError in adding title to ppt slide in python

Viewed 41

I have been writing a python code for insertion of pictures from a folder into a ppt slide accepted as input from user, and I am getting attribute error for trying to add the image name as title of the slide on which the image is set. The code is :

from pptx import Presentation
import os
import sys
from pptx.util import Inches

def ppt_creation_using_snaps(folder_loc, ppt_loc):
    ppt = Presentation(ppt_loc)
    #folder = open(folder_loc)
    folder_list = os.listdir(folder_loc)
    #folder_list.sort()

    for image in folder_list:
        if image.endswith(".png"):
           slide = ppt.slides.add_slide(ppt.slide_layouts[0])
           slide.shapes.title.text = ''.join(element for element in image if not element.isdigit())
           #slide.shapes.title.text = str(image)
           pic = slide.shapes.add_picture(folder_loc + '\\' + image,Inches(0),Inches(0),Inches(9.5))
           #Title = sl.shapes.title
       
    ppt.save(ppt_loc)

When I am executing the code, it shows the following error:

enter image description here

Please help me out for this

0 Answers
Related