from pptx import Presentation
from pptx.util import Pt
from docx.shared import Inches
prs=Presentation()
slide=prs.slides.add_slide(prs.slide_layouts[1])
shape_txt=slide.shapes.placeholders
shape_txt[0].text='this is title'
shape_txt[1].text='this is sub title'
new_para=shape_txt[1].text_frame.add_paragraph()
def para_set(new_para,txt,level=1,size=22,bold=False,italic=False,underline=False):
new_para.text = txt
new_para.level = level
new_para.font.size = Pt(size)
new_para.font.bold = bold
new_para.font.italic = italic
new_para.font.underline = underline
def add_txt_box(slide,txt,left,top,width,height):
textbox=slide.shapes.add_textbox(left,top,width,height)
textbox.text=txt
new_para=textbox.text_frame.add_paragraph()
new_para.text="This is a second paragraph!"
def add_pic(slide,pic,left,top,width,height):
slide.shapes.add_picture(pic,left,top,width,height)
table=slide.shapes.add_table(2,3,Inches(3.5),Inches(4.5),Inches(5),Inches(1))
para_set(new_para,'新段落')
add_txt_box(slide,'new text',Inches(4),Inches(1.8),Inches(5),Inches(1))
add_pic(slide,'123.png',Inches(1),Inches(4.5),Inches(2),Inches(2))
prs.save('test.pptx')