[Python] How to Add or Remove Background from PowerPoint Slide Master
When preparing for a professional presentation, it is essential to adjust the background of the PowerPoint to make slides attractive and aesthetic. The slide master, which controls the overall layout and design of all slides in a presentation, allows you to set or remove backgrounds across multiple slides.
If you want to create a clean look or add a new background for your presentation, you should check out this page. This guide will show you how to add or remove background from PowerPoint slide master programmatically in Python.
Prepare for tasks
To accomplish these tasks, we are going to use Spire.Presentation for Python. It is a comprehensive Python library with multiple features.
The presentation control enables you to effortlessly perform nearly all operations in Python that are typically done using Microsoft PowerPoint, such as format converting, adding or removing slides, and so on. This includes the ability to set or remove background in slide master, which we will cover later in the next section.
You can install Spire.Presentation for Python from PyPI using the pip command below:
pip install Spire.Presentation
If you have already installed it and would like to upgrade it to the newest version, please use the following command:
pip install - upgrade Spire.Presenation
How to Add a Background Image in PowerPoint Slide Master with Python
After preparing for tasks, it is time to get to the point. Adding an image to the background in PowerPoint slide masters enhances the aesthetics of the presentation and also ensures consistency in the appearance throughout all slides. With Python, you can easily automate this process to save time and energy when working with a presentation that has multiple slides.
This section will introduce how to add a background image in PowerPoint slide master with Python, providing detailed instructions as well as a code example. Let’s check it out.
Steps to set PowerPoint master slide background as images:
Create an object of the Presentation class and use the Presentation.LoadFromFile() method to open the PowerPoint presentation from the disk.
Get the slide master to be modified with the Presentation.Masters[] property.
Access the background of the slide master by calling the Master.SlideBackground property.
Set the background type to Custom, and the fill mode to Picture.
Add the background image to the image collection.
Add a background image in the PowerPoint slide master with the SlideBackground.Fill.PictureFill.Picture.EmbedImage property.
Save the resulting document with the Presentation.SaveToFile() method, and release the resources.
Here is the code example of adding an image background to the third slide master in PowerPoint:
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the sample file from the disk
presentation.LoadFromFile("presentation.pptx")
# Get the third slide master
master = presentation.Masters[2]
# Access the background of the slide master
SlideBackground = master.SlideBackground
# Set the slide master background style to custom
master.SlideBackground.Type = BackgroundType.Custom
# Set the fill mode of the background to Picture
SlideBackground.Fill.FillType = FillFormatType.Picture
# Add an image to the image collection of the presentation
stream = Stream("bg.png")
imageData = presentation.Images.AppendStream(stream)
# Set the image as the slide master's background
SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch
SlideBackground.Fill.PictureFill.Picture.EmbedImage = imageData
# Save the result presentation
presentation.SaveToFile("imagebackground.pptx", FileFormat.Pptx2013)
# Release resources
presentation.Dispose()
You may also like >> Add or Remove background from PowerPoint Slides
How to Set Background Color in PowerPoint Slide Master
In addition to using image backgrounds, setting a color background is another effective way to improve presentations. Compared to picture backgrounds, color backgrounds offer a cleaner, more focused look, allowing your audience to concentrate on the content without being distracted. At the same time, a well-chosen color background can make your slides more visually appealing and cohesive than leaving them without any background at all, striking a balance between simplicity and aesthetic appeal.
Set the Background Color to be Solid
There are normally two styles of color backgrounds, so let’s first go through how to a solid background color in PowerPoint. Solid color is clean and helps to highlight your key points.
Steps to set a solid color as the background of slide masters:
Create an instance of the Presentation class and load a PowerPoint document from the file path using the Presentation.LoadFromFile() method.
Get the slide master with the Presentation.Masters[] property.
Access the background of the slide master using the Master.SlideBackground property.
Set the background type to Custom.
Set the fill type to be a solid color with the SlideBackground.Fill.FillType property.
Apply the color background using the SlideBackground.Fill.SolidColor.Color property.
Store the modified document and release the resources.
Below is the code example for setting the background of the 3rd slide master to be dark sea green:
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the sample file from the disk
presentation.LoadFromFile("presentation.pptx")
# Get the third slide master
master = presentation.Masters[2]
# Access the background of the slide master
SlideBackground = master.SlideBackground
# Set the slide master background style to custom
master.SlideBackground.Type = BackgroundType.Custom
# Set the fill mode of the background to Picture
SlideBackground.Fill.FillType = FillFormatType.Solid
# Set a color as the background color
SlideBackground.Fill.SolidColor.Color = Color.get_DarkSeaGreen()
# Save the result presentation
presentation.SaveToFile("solidcolor_background.pptx", FileFormat.Pptx2013)
# Release resources
presentation.Dispose()
Set the Background Color to be Gradient
A gradient color background offers a more dynamic look compared to a solid color background. It is also a good way to differentiate content. For example, if you have a single slide covering two distinct topics, a gradient background can subtly separate the sections, making the content more visually organized and easier to follow.
Steps to set a gradient color as the background of PowerPoint slide masters:
Create a Presentation instance and read the PowerPoint document using the Presentation.LoadFromFile() method.
Get the slide master with the Presentation.Masters[] property.
Access the background of the slide master using the Master.SlideBackground property.
Set the background type to Custom.
Set the fill type to be a gradient color with the SlideBackground.Fill.FillType property.
Apply gradient color as the background using the SlideBackground.Fill.Gradient.GradientStops.AppendByColor() method.
Save the document as a new presentation with the Presentation.SaveToFile() method and release resources.
Here is an example of setting the background color to a dark sea green to honeydew gradient:
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the sample file from the disk
presentation.LoadFromFile("presentation.pptx")
# Get the third slide master
master = presentation.Masters[2]
# Access the background of the slide master
SlideBackground = master.SlideBackground
# Set the slide master background style to custom
master.SlideBackground.Type = BackgroundType.Custom
# Set the fill mode of the background to Picture
SlideBackground.Fill.FillType = FillFormatType.Gradient
# Set colors as the gradient background color
SlideBackground.Fill.Gradient.GradientStops.AppendByColor(0.1,Color.get_DarkSeaGreen())
SlideBackground.Fill.Gradient.GradientStops.AppendByColor(0.7,Color.get_Honeydew())
# Save the result presentation
presentation.SaveToFile("gradientcolor_background.pptx", FileFormat.Pptx2013)
# Release resources
presentation.Dispose()
How to Remove Background from PowerPoint Slide Master
There may be times when you need to remove PowerPoint master slide backgrounds. It could be because the current background no longer fits the presentation's theme, or you simply want a clean slate to apply a new design.
Remove background images and colors can be finished in the same way. In this part, we'll walk you through the steps to efficiently remove the background from PowerPoint slide masters using Python.
Steps to remove background from PowerPoint slide master:
Create an object for the Presentation class and open the PowerPoint document with the Presentation.LoadFromFile() method.
Get the slide master using the Presentation.Masters[] property.
Access the background of the slide master using the Master.SlideBackground property.
Remove the background of slide masters by calling the Master.SlideBackground.Type property and set it to None.
Save the processed document and release resources.
Below is a code example of removing the background from the 4th slide master:
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load the sample file from the disk
presentation.LoadFromFile("presentation.pptx")
# Get the fourth slide master
master = presentation.Masters[3]
# Access the background of the slide master
SlideBackground = master.SlideBackground
# Set the slide master background style to custom
master.SlideBackground.Type = BackgroundType.none
# Save the result presentation
presentation.SaveToFile("remove_background.pptx", FileFormat.Pptx2013)
# Release resources
presentation.Dispose()
The Conclusion
This article illustrates adding or removing background from PowerPoint slide masters in Python. This page has three main parts: adding an image background, adding background color, and removing slide masters’ backgrounds. Each part comes with a step-by-step guide and a code example for your reference. Start to make a better presentation with Spire.Presentation in Python now!
Subscribe to my newsletter
Read articles from Casie Liu directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by