Python pptx-将图片插入形状&;动画
我正在尝试使用python pptx制作python脚本,但我很难将图片插入形状中。基本上,我需要它使图片透明() 还有一件事,我想在演示文稿中添加一个按钮,用于显示/隐藏图片(尝试用python制作)。我不知道如何在python pptx中使用动画,你能帮我吗 非常感谢,谢谢。 拉兹 添加我用于制作透明形状的代码(只需在其中插入图片):Python pptx-将图片插入形状&;动画,python,animation,powerpoint,shapes,python-pptx,Python,Animation,Powerpoint,Shapes,Python Pptx,我正在尝试使用python pptx制作python脚本,但我很难将图片插入形状中。基本上,我需要它使图片透明() 还有一件事,我想在演示文稿中添加一个按钮,用于显示/隐藏图片(尝试用python制作)。我不知道如何在python pptx中使用动画,你能帮我吗 非常感谢,谢谢。 拉兹 添加我用于制作透明形状的代码(只需在其中插入图片): 仍然相关,我想得到你的帮助。有人能帮我吗?仍然相关,我想得到你的帮助。有人能帮我吗? from pptx import Presentation from p
仍然相关,我想得到你的帮助。有人能帮我吗?仍然相关,我想得到你的帮助。有人能帮我吗?
from pptx import Presentation
from pptx.oxml.xmlchemy import OxmlElement
from pptx.util import Cm
from pptx.enum.shapes import MSO_SHAPE
from pptx.dml.color import RGBColor
def SubElement(parent, tagname, **kwargs):
element = OxmlElement(tagname)
element.attrib.update(kwargs)
parent.append(element)
return element
def _set_shape_transparency(shape, alpha):
""" Set the transparency (alpha) of a shape"""
ts = shape.fill._xPr.solidFill
sF = ts.get_or_change_to_srgbClr()
sE = SubElement(sF, 'a:alpha', val=str(alpha))
## Create presentation
prs = Presentation()
## Add a slide (empty slide layout)
slide = prs.slides.add_slide(prs.slide_layouts[6])
##Add a blue box to the slide
# MSO_FILL_TYPE = MSO_FILL.PICTURE
blueBox = slide.shapes.add_shape(autoshape_type_id=MSO_SHAPE.RECTANGLE,
left=Cm(0),
top=Cm(0.54),
height=Cm(17.97),
width=Cm(25.4))
## Make the box blue
blueBoxFill = blueBox.fill
blueBoxFill.solid()
blueBoxFillColour = blueBoxFill.fore_color
blueBoxFillColour.rgb = RGBColor(0,176,240)
## Set the transparency of the blue box to 56%
_set_shape_transparency(blueBox,44000)
## Save the presentation
prs.save('test.pptx')