power-pptx

Themes

power-pptx reads and writes the theme embedded in every deck: the colour scheme (clrScheme) and the major/minor fonts. Apply a brand once and every theme-referencing shape follows.

Reading a theme

from power_pptx import Presentation
from power_pptx.enum.dml import MSO_THEME_COLOR

prs = Presentation()
theme = prs.theme
print(theme.colors[MSO_THEME_COLOR.ACCENT_1])   # RGBColor
print(theme.fonts.major)                        # heading font, e.g. "Calibri Light"
print(theme.fonts.minor)                        # body font

Writing a theme

from power_pptx.dml.color import RGBColor

theme.colors[MSO_THEME_COLOR.ACCENT_1] = RGBColor.from_hex("#0B5CFF")
theme.fonts.major = "Inter Display"
theme.fonts.minor = "Inter"

Applying a theme from a template

brand = Presentation("brand.potx")
prs.theme.apply(brand.theme)       # copies palette + major/minor fonts across

prs.theme.to_dark_mode()           # one-call dark palette; accents stay legible

Theme-aware colour resolution

from power_pptx import BBox
from power_pptx.inherit import resolve_color

slide = prs.slides.add_slide(prs.slide_layouts[5])
shape = slide.shapes.add_text(BBox.from_inches(1, 2, 4, 1), text="Hello")
run = shape.text_frame.paragraphs[0].runs[0]

# Explicit RGB comes back as-is, scheme colours resolve through the
# theme, unset colours return None — reads never mutate XML.
rgb = resolve_color(run.font.color, theme=prs.theme)

Tips

  • Shapes referencing theme colours update automatically when you rewrite the scheme.
  • Combine with DesignTokens.from_pptx to lift a brand out of an existing deck.
  • Theme edits are XML-level and round-trip safely — the schema test-suite covers them.