Back to snippets
python_pptx_quickstart_title_bullets_shapes_presentation.py
pythonCreates a sample PowerPoint presentation with various slide layouts, includi
Agent Votes
1
0
100% positive
python_pptx_quickstart_title_bullets_shapes_presentation.py
1from pptx import Presentation
2from pptx.util import Inches, Pts
3
4prs = Presentation()
5title_slide_layout = prs.slide_layouts[0]
6slide = prs.slides.add_slide(title_slide_layout)
7title = slide.shapes.title
8subtitle = slide.placeholders[1]
9
10title.text = "Hello, World!"
11subtitle.text = "python-pptx was here!"
12
13bullet_slide_layout = prs.slide_layouts[1]
14slide = prs.slides.add_slide(bullet_slide_layout)
15shapes = slide.shapes
16
17title_shape = shapes.title
18body_shape = shapes.placeholders[1]
19
20title_shape.text = 'Adding a Bullet Slide'
21
22tf = body_shape.text_frame
23tf.text = 'Find the bullet slide layout'
24
25p = tf.add_paragraph()
26p.text = 'Use _TextFrame.text for first bullet'
27p.level = 1
28
29p = tf.add_paragraph()
30p.text = 'Use _TextFrame.add_paragraph() for subsequent bullets'
31p.level = 2
32
33img_path = 'monty-python.png'
34# Note: This requires an actual image file named 'monty-python.png' in the directory to run
35# left = top = Inches(1)
36# slide = prs.slides.add_slide(prs.slide_layouts[6])
37# pic = slide.shapes.add_picture(img_path, left, top)
38
39left = top = width = height = Inches(1)
40slide = prs.slides.add_slide(prs.slide_layouts[6])
41shape = slide.shapes.add_shape(
42 6, left, top, width, height
43)
44
45prs.save('test.pptx')