Set Background of PowerPoint PPT Slides in Python

PowerPoint allows you to set different types of slide backgrounds in the presentations. For example, you can set an image, a solid color, etc. as background. In this article, we will show you how to set the background of PowerPoint PPT slides in Python. We will explicitly cover how to fill a PPT slide’s background with an image, color, or a gradient programmatically.

Python Library to Set Slide Background in PowerPoint

Aspose.Slides for Python is a popular and feature-rich library to create and manipulate PowerPoint presentations. We will utilize this library to set slide backgrounds in our PowerPoint presentations. To install the library from PyPI, you can use the following command.

> pip install aspose.slides

Set Image as PPT Slide Background in Python

The following are the steps to set a background image in a PowerPoint PPT/PPTX slide in Python.

  • First, use Presentation class to load or create the PPT/PPTX presentation.
  • Then, get reference of the desired slide from Presentation.slides collection.
  • Set slide background’s fill type to FillType.PICTURE.
  • Set fill mode of picture to PictureFillMode.STRETCH.
  • Add image to the collection of presentation using Presentation.images.add_image() method.
  • Set background image of the slide using Slide.background.fill_format.picture_fill_format.picture.image property.
  • Finally, save the updated presentation using Presentation.save(string, SaveFormat) method.

The following code sample shows how to set background image of PowerPoint PPT slides in Python.

The following screenshot shows the resultant PPT slide after adding background image.

Set Image as PPT Slide Background in Python

Set Background Color of PPT Slides in Python

The following are the steps to set the background color of the slides in a PowerPoint PPT using Python.

  • First, load or create the PowerPoint PPT/PPTX using Presentation class.
  • Set slide background’s fill type to FillType.SOLID.
  • Then, set the background color of slide using Slide.background.fill_format.solid_fill_color.color property.
  • Finally, save the updated presentation using Presentation.save(string, SaveFormat) method.

The following code sample shows how to set the background color of a PPT slide in Python.

Set Background Color of Master Slide in Python

You can also set the background of the master slide that will be applied to all the slides in the presentation. The following are the steps to change the background color of the master slide in Python.

  • First, load or create the PowerPoint PPT/PPTX using Presentation class.
  • Set master slide background’s fill type to FillType.SOLID.
  • Then, set the background color of master slide using MasterSlide.background.fill_format.solid_fill_color.color property.
  • Finally, save the updated presentation using Presentation.save(string, SaveFormat) method.

The following code sample shows how to change the background color of the master slide in PowerPoint PPT.

Set Gradient as PPT Slide Background in Python

You can also set the gradient background of the PPT slides using Aspose.Slides for Python, as demonstrated in the steps below.

  • First, load or create the PowerPoint PPT/PPTX using Presentation class.
  • Set slide background’s fill type to FillType.GRADIENT.
  • Then, set the background gradient format using Slide.background.fill_format.gradient_format.tile_flip property.
  • Finally, save the updated presentation using Presentation.save(string, SaveFormat) method.

The following code sample shows how to set the gradient background of PPT slides in Python.

The following screenshot shows the gradient background of the slide.

Set Gradient Background Color of Slides in Python

Get a Free API License

You can use Aspose.Slides for Python without evaluation limitations by requesting a temporary license.

Conclusion

In this article, you have learned how to set the background color or image of slides in PowerPoint PPT using Python. Furthermore, you have seen how to set gradient background of normal or master slides in PowerPoint presentations. You can visit the documentation to explore other features of Aspose.Slides for Python. Also, you can feel free to let us know about your queries via our forum.

See Also