I’m using the python-pptx module to create presentations. How can I change the font properties only for a part of the text?
I currently change the font like this:
JavaScript
x
16
16
1
# first create text for shape
2
ft = pres.slides[0].shapes[0].text_frame
3
ft.clear()
4
p = ft.paragraphs[0]
5
run = p.add_run()
6
run.text = "text"
7
8
# change font
9
from pptx.dml.color import RGBColor
10
from pptx.util import Pt
11
12
font = run.font
13
font.name = 'Lato'
14
font.size = Pt(32)
15
font.color.rgb = RGBColor(255, 255, 255)
16
Thanks!
Advertisement
Answer
In PowerPoint, font properties are applied to a run. In a way, it is what defines a run; a “run” of text sharing the same font treatment, including typeface, size, color, bold/italic, etc.
So to make two bits of text look differently, you need to make them separate runs.