2

I am trying to create a few shapes using python-pptx module in Python.

I have got the shapes created however I am unable to edit the font color for the text inside shape. By default it displays in white color. I am trying to see how could I change the text color. Given below is what I have built thus far:

left = Inches(1.0)
top = Inches(3.9)
width = Inches(1.2)
height = Inches(2.5)
shape = shapes.add_shape(
MSO_SHAPE.RECTANGLE, left, top, width, height
)
fill = shape.fill
fill.solid()
fill.fore_color.rgb = RGBColor(226, 206, 72)  # This RGB code is the background color that I want the shape to be in 
fill.fore_color.brightness = -0.3
text_frame = shape.text_frame
text_frame.clear()
p = text_frame.paragraphs[0]
run = p.add_run()
run.text = 'Test message'
font = run.font
font.name = 'Arial'
font.size = Pt(16)
font.bold = True
fedorqui
  • 275,237
  • 103
  • 548
  • 598
dark horse
  • 447
  • 1
  • 6
  • 17

1 Answers1

2

Looking at the documentation, you should be able to do this by adding one line to your code (at the bottom):

font.color.rgb = RGBColor(0x00, 0x00, 0x00)        # this would be black

Note: remember, to use RGBColor, you would have to import it:

from pptx.dml.color import RGBColor
Joseph Hansen
  • 12,665
  • 8
  • 50
  • 68