python-pptx 学习笔记 Shapes

Shapes API

Auto Shapes

from pptx.enum.shapes import MSO_SHAPE

#1.添加一个图形
shapes = slide.shapes
left = top = width = height = Inches(1.0)
shape = shapes.add_shape(
    MSO_SHAPE.ROUNDED_RECTANGLE, left, top, width, height
)
#2.访问图形的位置
shape.left, shape.top, shape.width, shape.height
#3.设置填充色
fill = shape.fill
fill.solid()
fill.fore_color.rgb = RGBColor(255, 0, 0)
#4.设置透明色
shape.fill.background()
#5.设置边框
line = shape.line
line.color.rgb = RGBColor(255, 0, 0)
line.color.brightness = 0.5  # 50% lighter
line.width = Pt(2.5)
#设置透明边框
line.fill.background()
#设置边框宽度
line.width = Pt(2.0)

posted on 2022-05-26 11:12  朝朝暮Mu  阅读(723)  评论(0)    收藏  举报