2016-07-05 25 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') 

Die mit "###### s" markierte Zeile soll die Form transparenter machen, wie in der pptx-Dokumentation beschrieben - es ist eine Eigenschaft shape.fill. Alles andere im Code funktioniert perfekt. Ich benutze Python 2.7 und die neueste pptx. Danke im Voraus für Ihre Hilfe.Wie füge ich Transparenz zur Form in Python pptx hinzu?

Antwort

0

FillFormat.transparency ist noch nicht implementiert. Der Teil der Dokumentation, wo Sie das gesehen haben, könnte eine Analyseseite gewesen sein, die ein Vorläufer der Entwicklung ist.

Es handelt sich hierbei die Analyse Seite: http://python-pptx.readthedocs.io/en/latest/dev/analysis/features/dml-fill.html?highlight=transparency

Dies ist die FillFormat (.fill) API, wie entwickelt: http://python-pptx.readthedocs.io/en/latest/api/dml.html#fillformat-objects

Sie jedoch lxml Anrufe aus dem FillFormat-Objekt verwenden, können die XML zu manipulieren, unter es. Sie wollen wahrscheinlich mit dem SPPR Elemente im .fill Elemente starten:

spPr = titleshape.fill._xPr 
print spPr.xml 

Hier ist ein Beispiel dafür zu tun, dass die Art der Sache: https://groups.google.com/forum/#!msg/python-pptx/UTkdemIZICw/qeUJEyKEAQAJ

Sie finden mehr, wenn Sie auf verschiedene Kombinationen von suchen die Begriffe python-pptx, OxmlElement, lxml und workaround function.

Verwandte Themen