如何在 python pptx 中更改标题颜色

how to change title color in python pptx

from pptx import Presentation
from pptx.dml.color import RGBColor
prs=Presentation()
title_slide_layout=prs.slide_layouts[0]
slide=prs.slides.add_slide(title_slide_layout)
background=slide.background
fill = background.fill
fill.solid()
fill.fore_color.rgb = RGBColor(59, 89, 152)
title=slide.shapes.title
subtitle=slide.placeholders[1]
title.text="title"
subtitle.text="Subtitle"
prs.save('mynewone.pptx')

我懒得换了,我换了背景,但我不工作

您需要处理形状的 text_frame 属性 并将该字体格式应用于 paragraphs。根据 documentation:

,我认为这应该可行
title.text_frame.paragraphs[0].font.color.rgb = RGBColor(59,89, 152)