2016-07-05 50 views
0
def new_presentation(): 
    prs=Presentation() 
    img="C:/Users/Dennis/Desktop/Tom-Hiddleston-4-1024x768.jpg" 
    mainsld=new_slide(prs, 6) 
    mainshp=mainsld.shapes 
    mainshp.add_picture(img, 0,0, Inches(10)) 
    titleshape=mainshp.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(1), Inches(10), Inches(1)) 
    titleshape.fill.solid() 
    titleshape.fill.fore_color.rgb=RGBColor(0x00,0x64,0x00) 
    titleshape.fill.transparency = 0.25 ##doesnt work???########################## 
    titleshape.line.fill.background() 
    titlebox=mainshp.add_textbox(Inches(1), Inches(0.8),Inches(1), Inches(1)).text_frame.add_paragraph() 
    titlebox.text="TOM HIDDLESTON" 
    titlebox.font.name="Calibri" 
    titlebox.font.size=Pt(36) 
    titlebox.font.color.rgb=RGBColor(0x90,0x90,0x00) 
    prs.save('test.pptx') 

"###### s"とマークされた行は、pptxドキュメントに書かれているようにシェイプをより透明にするためのもので、shape.fillプロパティです。コード内の他のすべてが完全に機能します。私はPython 2.7と最新のpptxを使用しています。事前にあなたの助けをありがとう。python pptxでシェイプを透明にするにはどうすればいいですか?

答えて

0

FillFormat.transparencyはまだ実装されていません。あなたが見たドキュメンテーションの部分は、開発の前兆である分析ページでした。

これは、解析ページです: http://python-pptx.readthedocs.io/en/latest/dev/analysis/features/dml-fill.html?highlight=transparency

開発し、これは、FillFormat(.fill)APIです: http://python-pptx.readthedocs.io/en/latest/api/dml.html#fillformat-objects

あなたはしかし、下にXMLを操作するためFillFormatオブジェクトからlxmlの呼び出しを使用することができますそれ。おそらく.fill要素でSPPR要素で開始したい:

spPr = titleshape.fill._xPr 
print spPr.xml 

ここではそういったことをすることの一例です: https://groups.google.com/forum/#!msg/python-pptx/UTkdemIZICw/qeUJEyKEAQAJ

あなたがのさまざまな組み合わせで検索する場合は、より多くのを見つけることができます用語「python-pptx」、「OxmlElement」、「lxml」および「workaround function」。

関連する問題