GradientStopCollection class

GradientStopCollection class

Contains a collection of GradientStop objects. To learn more, visit the Working with Graphic Elements documentation article.

You do not create instances of this class directly. Use the Fill.gradient_stops property to access gradient stops of fill objects.


__getitem__(index)Gets or sets a GradientStop object in the collection.


countGets an integer value indicating the number of items in the collection.


add(gradient_stop)Adds a specified GradientStop to a gradient.
insert(index, gradient_stop)Inserts a GradientStop to the collection at a specified index.
remove(gradient_stop)Removes a specified GradientStop from the collection.
remove_at(index)Removes a GradientStop from the collection at a specified index.


Shows how to add gradient stops to the gradient fill.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

shape = builder.insert_shape(aw.drawing.ShapeType.RECTANGLE, 80, 80)
shape.fill.two_color_gradient(,, aw.drawing.GradientStyle.HORIZONTAL, aw.drawing.GradientVariant.VARIANT2)

# Get gradient stops collection.
gradient_stops = shape.fill.gradient_stops

# Change first gradient stop.
gradient_stops[0].color = drawing.Color.aqua
gradient_stops[0].position = 0.1
gradient_stops[0].transparency = 0.25

# Add new gradient stop to the end of collection.
gradient_stop = aw.drawing.GradientStop(drawing.Color.brown, 0.5)

# Remove gradient stop at index 1.
# And insert new gradient stop at the same index 1.
gradient_stops.insert(1, aw.drawing.GradientStop(drawing.Color.chocolate, 0.75, 0.3))

# Remove last gradient stop in the collection.
gradient_stop = gradient_stops[2]

self.assertEqual(2, gradient_stops.count)
self.assertEqual(drawing.Color.from_argb(255, 0, 255, 255), gradient_stops[0].base_color);

self.assertEqual(drawing.Color.aqua.to_argb(), gradient_stops[0].color.to_argb())
self.assertAlmostEqual(0.1, gradient_stops[0].position, delta=0.01)
self.assertAlmostEqual(0.25, gradient_stops[0].transparency, delta=0.01)

self.assertEqual(drawing.Color.chocolate.to_argb(), gradient_stops[1].color.to_argb())
self.assertAlmostEqual(0.75, gradient_stops[1].position, delta=0.01)
self.assertAlmostEqual(0.3, gradient_stops[1].transparency, delta=0.01)

# Use the compliance option to define the shape using DML
# if you want to get "gradient_stops" property after the document saves.
save_options = aw.saving.OoxmlSaveOptions()
save_options.compliance = aw.saving.OoxmlCompliance.ISO29500_2008_STRICT + "Shape.gradient_stops.docx", save_options)

See Also