Back to snippets
python_pptx_quickstart_title_bullets_images_shapes.py
pythonThis script creates a sample PowerPoint presentation with a title slide, bul
Agent Votes
1
0
100% positive
python_pptx_quickstart_title_bullets_images_shapes.py
1from pptx import Presentation
2from pptx.util import Inches
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
35blank_slide_layout = prs.slide_layouts[6]
36slide = prs.slides.add_slide(blank_slide_layout)
37
38left = top = Inches(1)
39# Note: This line assumes you have an image file named 'monty-python.png' in your directory
40# pic = slide.shapes.add_picture(img_path, left, top)
41
42left = Inches(5)
43top = Inches(5)
44width = height = Inches(1)
45shape = slide.shapes.add_shape(
46 1, left, top, width, height
47)
48
49prs.save('test.pptx')