|
from pptx import Presentation |
|
from pptx.util import Inches |
|
from pptx.enum.chart import XL_CHART_TYPE |
|
|
|
# Create a presentation object |
|
prs = Presentation() |
|
|
|
# Add a title slide |
|
slide_layout = prs.slide_layouts[0] # 0 is the layout for the title slide |
|
slide = prs.slides.add_slide(slide_layout) |
|
title = slide.shapes.title |
|
subtitle = slide.placeholders[1] |
|
|
|
title.text = "Welcome to the Presentation" |
|
subtitle.text = "This presentation contains text, a table, and a chart." |
|
|
|
# Add a slide with a title and content |
|
slide_layout = prs.slide_layouts[1] # 1 is the layout for title and content |
|
slide = prs.slides.add_slide(slide_layout) |
|
title = slide.shapes.title |
|
content = slide.placeholders[1] |
|
|
|
title.text = "Agenda" |
|
content.text = "1. Introduction\n2. Main Content\n3. Conclusion" |
|
|
|
# Add a slide with a table |
|
slide_layout = prs.slide_layouts[5] # 5 is the layout for title and content |
|
slide = prs.slides.add_slide(slide_layout) |
|
title = slide.shapes.title |
|
title.text = "Data Table" |
|
|
|
# Define table dimensions |
|
rows = 3 |
|
cols = 4 |
|
left = Inches(2) |
|
top = Inches(2) |
|
width = Inches(6) |
|
height = Inches(1.5) |
|
|
|
# Add table |
|
table = slide.shapes.add_table(rows, cols, left, top, width, height).table |
|
|
|
# Set column headings |
|
table.columns[0].width = Inches(1.5) |
|
table.columns[1].width = Inches(1.5) |
|
table.columns[2].width = Inches(1.5) |
|
table.columns[3].width = Inches(1.5) |
|
|
|
table.cell(0, 0).text = 'Header 1' |
|
table.cell(0, 1).text = 'Header 2' |
|
table.cell(0, 2).text = 'Header 3' |
|
table.cell(0, 3).text = 'Header 4' |
|
|
|
# Add data to the table |
|
table.cell(1, 0).text = 'Data 1' |
|
table.cell(1, 1).text = 'Data 2' |
|
table.cell(1, 2).text = 'Data 3' |
|
table.cell(1, 3).text = 'Data 4' |
|
|
|
table.cell(2, 0).text = 'Data 5' |
|
table.cell(2, 1).text = 'Data 6' |
|
table.cell(2, 2).text = 'Data 7' |
|
table.cell(2, 3).text = 'Data 8' |
|
|
|
prs.save('combined_presentation.pptx') |
Run: pip install python-pptx
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
prs = Presentation()
prs.slide_width = Inches(13.33) # 16:9 widescreen
prs.slide_height = Inches(7.5)
blank_layout = prs.slide_layouts[6]
def set_bg(slide, r, g, b):
bg = slide.background
fill = bg.fill
fill.solid()
fill.fore_color.rgb = RGBColor(r, g, b)
--- SLIDE 1: Title & Hook ---
slide1 = prs.slides.add_slide(blank_layout)
set_bg(slide1, 230, 245, 255) # Soft Sky Blue
tx_box1 = slide1.shapes.add_textbox(Inches(1.5), Inches(2.0), Inches(10.33), Inches(3.5))
tf1 = tx_box1.text_frame
p1 = tf1.paragraphs[0]
p1.text = "The Swing"
p1.font.size = Pt(64)
p1.font.bold = True
p1.font.color.rgb = RGBColor(24, 76, 120)
p1.alignment = PP_ALIGN.CENTER
p2 = tf1.add_paragraph()
p2.text = "By Robert Louis Stevenson\nGrade 2 English • Interactive Smart Board Lesson"
p2.font.size = Pt(28)
p2.font.color.rgb = RGBColor(80, 80, 80)
p2.alignment = PP_ALIGN.CENTER
--- SLIDE 2: Illustrated Poem Text ---
slide2 = prs.slides.add_slide(blank_layout)
set_bg(slide2, 255, 253, 240) # Warm Light Yellow
title2 = slide2.shapes.add_textbox(Inches(1.0), Inches(0.6), Inches(11.33), Inches(1.0))
p_t2 = title2.text_frame.paragraphs[0]
p_t2.text = "Let's Read & Swing Together!"
p_t2.font.size = Pt(36)
p_t2.font.bold = True
p_t2.font.color.rgb = RGBColor(20, 80, 50)
poem_box = slide2.shapes.add_textbox(Inches(1.0), Inches(1.8), Inches(11.33), Inches(5.0))
tf2 = poem_box.text_frame
stanzas = [
"How do you like to go up in a swing,\nUp in the air so blue?\nOh, I do think it the pleasantest thing\nEver a child can do!",
"Up in the air and over the wall,\nTill I can see so wide,\nRivers and trees and cattle and all\nOver the countryside—",
"Till I look down on the garden green,\nDown on the roof so brown—\nUp in the air I go flying again,\nUp in the air and down!"
]
for stanza in stanzas:
p = tf2.add_paragraph()
p.text = stanza
p.font.size = Pt(20)
p.font.color.rgb = RGBColor(40, 40, 40)
p.space_after = Pt(14)
--- SLIDE 3: Interactive Rhyme Match ---
slide3 = prs.slides.add_slide(blank_layout)
set_bg(slide3, 245, 240, 255) # Light Lavender
title3 = slide3.shapes.add_textbox(Inches(1.0), Inches(0.6), Inches(11.33), Inches(1.0))
p_t3 = title3.text_frame.paragraphs[0]
p_t3.text = "Touch & Match: The Rhyme Challenge!"
p_t3.font.size = Pt(36)
p_t3.font.bold = True
p_t3.font.color.rgb = RGBColor(90, 40, 140)
col1 = slide3.shapes.add_textbox(Inches(2.0), Inches(2.2), Inches(4.0), Inches(4.5))
tf_c1 = col1.text_frame
for word in ["Swing", "Blue", "Wall", "Brown"]:
p = tf_c1.add_paragraph()
p.text = word
p.font.size = Pt(30)
p.font.bold = True
p.font.color.rgb = RGBColor(0, 102, 204)
p.space_after = Pt(24)
col2 = slide3.shapes.add_textbox(Inches(7.5), Inches(2.2), Inches(4.0), Inches(4.5))
tf_c2 = col2.text_frame
for target in ["Thing", "Do", "All", "Down"]:
p = tf_c2.add_paragraph()
p.text = f"➔ {target}"
p.font.size = Pt(30)
p.font.bold = True
p.font.color.rgb = RGBColor(204, 51, 0)
p.space_after = Pt(24)
--- SLIDE 4: Review & Home Mission ---
slide4 = prs.slides.add_slide(blank_layout)
set_bg(slide4, 240, 255, 245) # Mint White
title4 = slide4.shapes.add_textbox(Inches(1.0), Inches(0.8), Inches(11.33), Inches(1.0))
p_t4 = title4.text_frame.paragraphs[0]
p_t4.text = "Colors & Home Mission"
p_t4.font.size = Pt(36)
p_t4.font.bold = True
p_t4.font.color.rgb = RGBColor(0, 120, 90)
body4 = slide4.shapes.add_textbox(Inches(1.5), Inches(2.2), Inches(10.33), Inches(4.5))
tf4 = body4.text_frame
items = [
"Colors from the Swing:",
" • Blue — Air / Sky",
" • Green — Garden",
" • Brown — Roof",
"",
"Home Mission:",
" 1. Draw a pretty swing tied to a big tree in your notebook.",
" 2. Write down your favorite rhyming pair below the drawing (e.g., Brown — Down)."
]
for item in items:
p = tf4.add_paragraph()
p.text = item
p.font.size = Pt(24)
p.font.color.rgb = RGBColor(50, 50, 50)
p.space_after = Pt(8)
prs.save("The_Swing_Microteaching.pptx")
print("Presentation generated successfully as 'The_Swing_Microteaching.pptx'")