Switch Slide Background Like PowerPoint Background Style Switching in Python

I want to switch the background like in the PowerPoint application. I have tried this way the code showing the picture, or your document: Presentation Theme|Aspose.Slides for Python Documentation

Give me a Python code for doing the same functionality as in the PowerPoint.

OS: Ubuntu 22
Language Python
version latest
image.png (127.1 KB)

@anantutkpd can you please be more specific about what you want to achieve or provide more details if you are experiencing some kind of error.
The code to set a background is this:

pres.masters[0].background.style_index = 2 //Where 0 is used for not fill

it is not working same as the ppt. I have tried 1 to 3. But it not working poperly as the ppt updated from the powerpoint.
when I set pres.masters[0].background.style_index = 1: image.png (69.5 KB)

when I set pres.masters[0].background.style_index = 2: image.png (68.2 KB)

when I set pres.masters[0].background.style_index = 3 image.png (73.7 KB)

But this output is differnt from the powerpoint generated one this is my original ppt:c0471309191b4847bdfc41cbdec58330.zip (51.7 KB)

@anantutkpd the fist image that you posted looks very similar to the presentation. Can you please post a presentation file with your expected result.

set 0: 20a3903c66234124be54c84b0f2fb827.zip (49.5 KB) (here the font colour not switching properly- not switching from white to black)
set 1: 1c7e66eaed604850b44ede02c8c16bbd.zip (51.7 KB)
set 2: 8fe9fa25566d4be791578b9d4cd56e1a.zip (51.4 KB)
set 3: 28fef60927ec4307a366379583626ead.zip (51.8 KB)

Try same thing from Powerpoint app it working properly.

@anantutkpd That is actually the expected behavior. When you set the StyleIndex to 0, you are indicating that you are not applying any background style, so the fonts will be retained as they are and the background will be removed.

PowerPoint app offers several Background Styles (12 by default) to choose from. The Background Styles not only modify the background, but also apply a color palette for the presentation, including the fonts. When you save a PowerPoint presentation, it usually includes metadata of the closest Background Styles based on the color scheme (usually 3). This metadata allows the PowerPoint app to recreate the Background Styles if they are not included by default in the app.

Aspose Slides allows you to access that metadata and modify the selected style from the available list. However, those styles tend to be related to the color scheme. So, if you want to make disruptive changes to the color scheme of an existing presentation, you would need to do it manually.

@eduardo.canal
How can I manually change the font color? Can you give me a code for change the font color for the entire ppt?

@anantutkpd using this code you can change the color of the text.

presentation = Presentation("C:\\Temp\\slides\\input.pptx")

presentation.masters[0].background.type = BackgroundType.OWN_BACKGROUND
presentation.masters[0].background.fill_format.fill_type = FillType.SOLID
presentation.masters[0].background.fill_format.solid_fill_color.color = drawing.Color.white

for slide in presentation.slides:
    for shape in slide.shapes:
        tf = shape.text_frame
        if tf:
            for p in tf.paragraphs:
                for por in p.portions:
                    por.portion_format.fill_format.solid_fill_color.color = drawing.Color.black
                    por.portion_format.fill_format.fill_type = FillType.SOLID

presentation.save("C:\\Temp\\slides\\output.pptx", SaveFormat.PPTX)