Shapes

The following classes provide access to the shapes that appear on a slide and the collections that contain them.

SlideShapes objects

The SlideShapes object is encountered as the shapes property of Slide.

class pptx.shapes.shapetree.SlideShapes[源代码]

Sequence of shapes appearing on a slide.

The first shape in the sequence is the backmost in z-order and the last shape is topmost. Supports indexed access, len(), index(), and iteration.

add_chart(chart_type, x, y, cx, cy, chart_data)

Add a new chart of chart_type to the slide.

The chart is positioned at (x, y), has size (cx, cy), and depicts chart_data. chart_type is one of the XL_CHART_TYPE enumeration values. chart_data is a ChartData object populated with the categories and series values for the chart.

Note that a GraphicFrame shape object is returned, not the Chart object contained in that graphic frame shape. The chart object may be accessed using the chart property of the returned GraphicFrame object.

add_connector(connector_type, begin_x, begin_y, end_x, end_y)

Add a newly created connector shape to the end of this shape tree.

connector_type is a member of the MSO_CONNECTOR_TYPE enumeration and the end-point values are specified as EMU values. The returned connector is of type connector_type and has begin and end points as specified.

add_group_shape(shapes=[])

Return a GroupShape object newly appended to this shape tree.

The group shape is empty and must be populated with shapes using methods on its shape tree, available on its .shapes property. The position and extents of the group shape are determined by the shapes it contains; its position and extents are recalculated each time a shape is added to it.

add_movie(movie_file, left, top, width, height, poster_frame_image=None, mime_type='video/unknown')[源代码]

Return newly added movie shape displaying video in movie_file.

EXPERIMENTAL. This method has important limitations:

  • The size must be specified; no auto-scaling such as that provided by add_picture() is performed.

  • The MIME type of the video file should be specified, e.g. ‘video/mp4’. The provided video file is not interrogated for its type. The MIME type video/unknown is used by default (and works fine in tests as of this writing).

  • A poster frame image must be provided, it cannot be automatically extracted from the video file. If no poster frame is provided, the default “media loudspeaker” image will be used.

Return a newly added movie shape to the slide, positioned at (left, top), having size (width, height), and containing movie_file. Before the video is started, poster_frame_image is displayed as a placeholder for the video.

add_ole_object(object_file, prog_id, left, top, width=None, height=None, icon_file=None)

Return newly-created GraphicFrame shape embedding object_file.

The returned graphic-frame shape contains object_file as an embedded OLE object. It is displayed as an icon at left, top with size width, height. width and height may be omitted when prog_id is a member of PROG_ID, in which case the default icon size is used. This is advised for best appearance where applicable because it avoids an icon with a “stretched” appearance.

object_file may either be a str path to the file or a file-like object (such as io.BytesIO) containing the bytes of the object file.

prog_id can be either a member of pptx.enum.shapes.PROG_ID or a str value like “Adobe.Exchange.7” determined by inspecting the XML generated by PowerPoint for an object of the desired type.

icon_file may either be a str path to an image file or a file-like object containing the image. The image provided will be displayed in lieu of the OLE object; double-clicking on the image opens the object (subject to operating-system limitations). The image file can be any supported image file. Those produced by PowerPoint itself are generally EMF and can be harvested from a PPTX package that embeds such an object. PNG and JPG also work fine.

add_picture(image_file, left, top, width=None, height=None)

Add picture shape displaying image in image_file.

image_file can be either a path to a file (a string) or a file-like object. The picture is positioned with its top-left corner at (top, left). If width and height are both None, the native size of the image is used. If only one of width or height is used, the unspecified dimension is calculated to preserve the aspect ratio of the image. If both are specified, the picture is stretched to fit, without regard to its native aspect ratio.

add_shape(autoshape_type_id, left, top, width, height)

Return new Shape object appended to this shape tree.

autoshape_type_id is a member of MSO_AUTO_SHAPE_TYPE e.g. MSO_SHAPE.RECTANGLE specifying the type of shape to be added. The remaining arguments specify the new shape’s position and size.

add_table(rows, cols, left, top, width, height)[源代码]

Add a GraphicFrame object containing a table with the specified number of rows and cols and the specified position and size. width is evenly distributed between the columns of the new table. Likewise, height is evenly distributed between the rows. Note that the .table property on the returned GraphicFrame shape must be used to access the enclosed Table object.

add_textbox(left, top, width, height)

Return newly added text box shape appended to this shape tree.

The text box is of the specified size, located at the specified position on the slide.

build_freeform(start_x=0, start_y=0, scale=1.0)

Return FreeformBuilder object to specify a freeform shape.

The optional start_x and start_y arguments specify the starting pen position in local coordinates. They will be rounded to the nearest integer before use and each default to zero.

The optional scale argument specifies the size of local coordinates proportional to slide coordinates (EMU). If the vertical scale is different than the horizontal scale (local coordinate units are “rectangular”), a pair of numeric values can be provided as the scale argument, e.g. scale=(1.0, 2.0). In this case the first number is interpreted as the horizontal (X) scale and the second as the vertical (Y) scale.

A convenient method for calculating scale is to divide a Length object by an equivalent count of local coordinate units, e.g. scale = Inches(1)/1000 for 1000 local units per inch.

property element

The lxml element proxied by this object.

index(shape)

Return the index of shape in this sequence.

Raises ValueError if shape is not in the collection.

property parent

The ancestor proxy object to this one. For example, the parent of a shape is generally the SlideShapes object that contains it.

property part

The package part containing this object

property placeholders

Instance of SlidePlaceholders containing sequence of placeholder shapes in this slide.

property title

The title placeholder shape on the slide or None if the slide has no title placeholder.

property turbo_add_enabled

True if “turbo-add” mode is enabled. Read/Write.

EXPERIMENTAL: This feature can radically improve performance when adding large numbers (hundreds of shapes) to a slide. It works by caching the last shape ID used and incrementing that value to assign the next shape id. This avoids repeatedly searching all shape ids in the slide each time a new ID is required.

Performance is not noticeably improved for a slide with a relatively small number of shapes, but because the search time rises with the square of the shape count, this option can be useful for optimizing generation of a slide composed of many shapes.

Shape-id collisions can occur (causing a repair error on load) if more than one Slide object is used to interact with the same slide in the presentation. Note that the Slides collection creates a new Slide object each time a slide is accessed (e.g. slide = prs.slides[0], so you must be careful to limit use to a single Slide object.

GroupShapes objects

The GroupShapes object is encountered as the shapes property of GroupShape.

class pptx.shapes.shapetree.GroupShapes[源代码]

The sequence of child shapes belonging to a group shape.

Note that this collection can itself contain a group shape, making this part of a recursive, tree data structure (acyclic graph).

add_chart(chart_type, x, y, cx, cy, chart_data)

Add a new chart of chart_type to the slide.

The chart is positioned at (x, y), has size (cx, cy), and depicts chart_data. chart_type is one of the XL_CHART_TYPE enumeration values. chart_data is a ChartData object populated with the categories and series values for the chart.

Note that a GraphicFrame shape object is returned, not the Chart object contained in that graphic frame shape. The chart object may be accessed using the chart property of the returned GraphicFrame object.

add_connector(connector_type, begin_x, begin_y, end_x, end_y)

Add a newly created connector shape to the end of this shape tree.

connector_type is a member of the MSO_CONNECTOR_TYPE enumeration and the end-point values are specified as EMU values. The returned connector is of type connector_type and has begin and end points as specified.

add_group_shape(shapes=[])

Return a GroupShape object newly appended to this shape tree.

The group shape is empty and must be populated with shapes using methods on its shape tree, available on its .shapes property. The position and extents of the group shape are determined by the shapes it contains; its position and extents are recalculated each time a shape is added to it.

add_ole_object(object_file, prog_id, left, top, width=None, height=None, icon_file=None)

Return newly-created GraphicFrame shape embedding object_file.

The returned graphic-frame shape contains object_file as an embedded OLE object. It is displayed as an icon at left, top with size width, height. width and height may be omitted when prog_id is a member of PROG_ID, in which case the default icon size is used. This is advised for best appearance where applicable because it avoids an icon with a “stretched” appearance.

object_file may either be a str path to the file or a file-like object (such as io.BytesIO) containing the bytes of the object file.

prog_id can be either a member of pptx.enum.shapes.PROG_ID or a str value like “Adobe.Exchange.7” determined by inspecting the XML generated by PowerPoint for an object of the desired type.

icon_file may either be a str path to an image file or a file-like object containing the image. The image provided will be displayed in lieu of the OLE object; double-clicking on the image opens the object (subject to operating-system limitations). The image file can be any supported image file. Those produced by PowerPoint itself are generally EMF and can be harvested from a PPTX package that embeds such an object. PNG and JPG also work fine.

add_picture(image_file, left, top, width=None, height=None)

Add picture shape displaying image in image_file.

image_file can be either a path to a file (a string) or a file-like object. The picture is positioned with its top-left corner at (top, left). If width and height are both None, the native size of the image is used. If only one of width or height is used, the unspecified dimension is calculated to preserve the aspect ratio of the image. If both are specified, the picture is stretched to fit, without regard to its native aspect ratio.

add_shape(autoshape_type_id, left, top, width, height)

Return new Shape object appended to this shape tree.

autoshape_type_id is a member of MSO_AUTO_SHAPE_TYPE e.g. MSO_SHAPE.RECTANGLE specifying the type of shape to be added. The remaining arguments specify the new shape’s position and size.

add_textbox(left, top, width, height)

Return newly added text box shape appended to this shape tree.

The text box is of the specified size, located at the specified position on the slide.

build_freeform(start_x=0, start_y=0, scale=1.0)

Return FreeformBuilder object to specify a freeform shape.

The optional start_x and start_y arguments specify the starting pen position in local coordinates. They will be rounded to the nearest integer before use and each default to zero.

The optional scale argument specifies the size of local coordinates proportional to slide coordinates (EMU). If the vertical scale is different than the horizontal scale (local coordinate units are “rectangular”), a pair of numeric values can be provided as the scale argument, e.g. scale=(1.0, 2.0). In this case the first number is interpreted as the horizontal (X) scale and the second as the vertical (Y) scale.

A convenient method for calculating scale is to divide a Length object by an equivalent count of local coordinate units, e.g. scale = Inches(1)/1000 for 1000 local units per inch.

property element

The lxml element proxied by this object.

index(shape)

Return the index of shape in this sequence.

Raises ValueError if shape is not in the collection.

property parent

The ancestor proxy object to this one. For example, the parent of a shape is generally the SlideShapes object that contains it.

property part

The package part containing this object

property turbo_add_enabled

True if “turbo-add” mode is enabled. Read/Write.

EXPERIMENTAL: This feature can radically improve performance when adding large numbers (hundreds of shapes) to a slide. It works by caching the last shape ID used and incrementing that value to assign the next shape id. This avoids repeatedly searching all shape ids in the slide each time a new ID is required.

Performance is not noticeably improved for a slide with a relatively small number of shapes, but because the search time rises with the square of the shape count, this option can be useful for optimizing generation of a slide composed of many shapes.

Shape-id collisions can occur (causing a repair error on load) if more than one Slide object is used to interact with the same slide in the presentation. Note that the Slides collection creates a new Slide object each time a slide is accessed (e.g. slide = prs.slides[0], so you must be careful to limit use to a single Slide object.

Shape objects in general

The following properties and methods are common to all shapes.

class pptx.shapes.base.BaseShape[源代码]

Base class for shape objects.

Subclasses include Shape, Picture, and GraphicFrame.

click_action[源代码]

ActionSetting instance providing access to click behaviors.

Click behaviors are hyperlink-like behaviors including jumping to a hyperlink (web page) or to another slide in the presentation. The click action is that defined on the overall shape, not a run of text within the shape. An ActionSetting object is always returned, even when no click behavior is defined on the shape.

property element

lxml element for this shape, e.g. a CT_Shape instance.

Note that manipulating this element improperly can produce an invalid presentation file. Make sure you know what you’re doing if you use this to change the underlying XML.

property has_chart

True if this shape is a graphic frame containing a chart object. False otherwise. When True, the chart object can be accessed using the .chart property.

property has_table

True if this shape is a graphic frame containing a table object. False otherwise. When True, the table object can be accessed using the .table property.

property has_text_frame

True if this shape can contain text.

property height

Read/write. Integer distance between top and bottom extents of shape in EMUs

property is_placeholder

True if this shape is a placeholder. A shape is a placeholder if it has a <p:ph> element.

property left

Read/write. Integer distance of the left edge of this shape from the left edge of the slide, in English Metric Units (EMU)

property name

Name of this shape, e.g. ‘Picture 7’

property placeholder_format

A _PlaceholderFormat object providing access to placeholder-specific properties such as placeholder type. Raises ValueError on access if the shape is not a placeholder.

property rotation

Read/write float. Degrees of clockwise rotation. Negative values can be assigned to indicate counter-clockwise rotation, e.g. assigning -45.0 will change setting to 315.0.

shadow[源代码]

ShadowFormat object providing access to shadow for this shape.

A ShadowFormat object is always returned, even when no shadow is explicitly defined on this shape (i.e. it inherits its shadow behavior).

property shape_id

Read-only positive integer identifying this shape.

The id of a shape is unique among all shapes on a slide.

property shape_type

Unique integer identifying the type of this shape, like MSO_SHAPE_TYPE.CHART. Must be implemented by subclasses.

property top

Read/write. Integer distance of the top edge of this shape from the top edge of the slide, in English Metric Units (EMU)

property width

Read/write. Integer distance between left and right extents of shape in EMUs

Shape objects (AutoShapes)

The following properties and methods are defined for AutoShapes, which include text boxes and placeholders.

class pptx.shapes.autoshape.Shape[源代码]

A shape that can appear on a slide.

Corresponds to the <p:sp> element that can appear in any of the slide-type parts (slide, slideLayout, slideMaster, notesPage, notesMaster, handoutMaster).

adjustments[源代码]

Read-only reference to AdjustmentCollection instance for this shape

property auto_shape_type

Enumeration value identifying the type of this auto shape, like MSO_SHAPE.ROUNDED_RECTANGLE. Raises ValueError if this shape is not an auto shape.

fill[源代码]

FillFormat instance for this shape, providing access to fill properties such as fill color.

property has_text_frame

True if this shape can contain text. Always True for an AutoShape.

line[源代码]

LineFormat instance for this shape, providing access to line properties such as line color.

property shape_type

Unique integer identifying the type of this shape, like MSO_SHAPE_TYPE.TEXT_BOX.

property text

Read/write. Unicode (str in Python 3) representation of shape text.

The returned string will contain a newline character ("\n") separating each paragraph and a vertical-tab ("\v") character for each line break (soft carriage return) in the shape’s text.

Assignment to text replaces all text previously contained in the shape, along with any paragraph or font formatting applied to it. A newline character ("\n") in the assigned text causes a new paragraph to be started. A vertical-tab ("\v") character in the assigned text causes a line-break (soft carriage-return) to be inserted. (The vertical-tab character appears in clipboard text copied from PowerPoint as its encoding of line-breaks.)

Either bytes (Python 2 str) or unicode (Python 3 str) can be assigned. Bytes can be 7-bit ASCII or UTF-8 encoded 8-bit bytes. Bytes values are converted to unicode assuming UTF-8 encoding (which also works for ASCII).

property text_frame

TextFrame instance for this shape.

Contains the text of the shape and provides access to text formatting properties.

AdjustmentCollection objects

An AutoShape is distinctive in that it can have adjustments, represented in the PowerPoint user interface as small yellow diamonds that each allow a parameter of the shape, such as the angle of an arrowhead, to be adjusted. The AdjustmentCollection object holds these adjustment values for an AutoShape, each of which is an Adjustment instance.

The AdjustmentCollection instance for an AutoShape is accessed using the Shape.adjustments property (read-only).

class pptx.shapes.autoshape.AdjustmentCollection(prstGeom)[源代码]

Sequence of Adjustment instances for an auto shape, each representing an available adjustment for a shape of its type. Supports len() and indexed access, e.g. shape.adjustments[1] = 0.15.

Adjustment objects

class pptx.shapes.autoshape.Adjustment(name, def_val, actual=None)[源代码]

An adjustment value for an autoshape.

An adjustment value corresponds to the position of an adjustment handle on an auto shape. Adjustment handles are the small yellow diamond-shaped handles that appear on certain auto shapes and allow the outline of the shape to be adjusted. For example, a rounded rectangle has an adjustment handle that allows the radius of its corner rounding to be adjusted.

Values are float and generally range from 0.0 to 1.0, although the value can be negative or greater than 1.0 in certain circumstances.

property effective_value

Read/write float representing normalized adjustment value for this adjustment. Actual values are a large-ish integer expressed in shape coordinates, nominally between 0 and 100,000. The effective value is normalized to a corresponding value nominally between 0.0 and 1.0. Intuitively this represents the proportion of the width or height of the shape at which the adjustment value is located from its starting point. For simple shapes such as a rounded rectangle, this intuitive correspondence holds. For more complicated shapes and at more extreme shape proportions (e.g. width is much greater than height), the value can become negative or greater than 1.0.

property val

Denormalized effective value (expressed in shape coordinates), suitable for using in the XML.

Connector objects

The following properties and methods are defined for Connector shapes:

class pptx.shapes.connector.Connector[源代码]

Connector (line) shape.

A connector is a linear shape having end-points that can be connected to other objects (but not to other connectors). A connector can be straight, have elbows, or can be curved.

begin_connect(shape, cxn_pt_idx)[源代码]

EXPERIMENTAL - The current implementation only works properly with rectangular shapes, such as pictures and rectangles. Use with other shape types may cause unexpected visual alignment of the connected end-point and could lead to a load error if cxn_pt_idx exceeds the connection point count available on the connected shape. That said, a quick test should reveal what to expect when using this method with other shape types.

Connect the beginning of this connector to shape at the connection point specified by cxn_pt_idx. Each shape has zero or more connection points and they are identified by index, starting with 0. Generally, the first connection point of a shape is at the top center of its bounding box and numbering proceeds counter-clockwise from there. However this is only a convention and may vary, especially with non built-in shapes.

property begin_x

Return the X-position of the begin point of this connector, in English Metric Units (as a Length object).

property begin_y

Return the Y-position of the begin point of this connector, in English Metric Units (as a Length object).

end_connect(shape, cxn_pt_idx)[源代码]

EXPERIMENTAL - The current implementation only works properly with rectangular shapes, such as pictures and rectangles. Use with other shape types may cause unexpected visual alignment of the connected end-point and could lead to a load error if cxn_pt_idx exceeds the connection point count available on the connected shape. That said, a quick test should reveal what to expect when using this method with other shape types.

Connect the ending of this connector to shape at the connection point specified by cxn_pt_idx.

property end_x

Return the X-position of the end point of this connector, in English Metric Units (as a Length object).

property end_y

Return the Y-position of the end point of this connector, in English Metric Units (as a Length object).

line[源代码]

LineFormat instance for this connector.

Provides access to line properties such as line color, width, and line style.

property shape_type

Member of MSO_SHAPE_TYPE identifying the type of this shape.

Unconditionally MSO_SHAPE_TYPE.LINE for a Connector object.

FreeformBuilder objects

The following properties and methods are defined for FreeformBuilder objects. A freeform builder is used to create a shape with custom geometry:

class pptx.shapes.freeform.FreeformBuilder[源代码]

Allows a freeform shape to be specified and created.

The initial pen position is provided on construction. From there, drawing proceeds using successive calls to draw line segments. The freeform shape may be closed by calling the close() method.

A shape may have more than one contour, in which case overlapping areas are “subtracted”. A contour is a sequence of line segments beginning with a “move-to” operation. A move-to operation is automatically inserted in each new freeform; additional move-to ops can be inserted with the .move_to() method.

add_line_segments(vertices, close=True)[源代码]

Add a straight line segment to each point in vertices.

vertices must be an iterable of (x, y) pairs (2-tuples). Each x and y value is rounded to the nearest integer before use. The optional close parameter determines whether the resulting contour is closed or left open.

Returns this FreeformBuilder object so it can be used in chained calls.

convert_to_shape(origin_x=0, origin_y=0)[源代码]

Return new freeform shape positioned relative to specified offset.

origin_x and origin_y locate the origin of the local coordinate system in slide coordinates (EMU), perhaps most conveniently by use of a Length object.

Note that this method may be called more than once to add multiple shapes of the same geometry in different locations on the slide.

move_to(x, y)[源代码]

Move pen to (x, y) (local coordinates) without drawing line.

Returns this FreeformBuilder object so it can be used in chained calls.

Picture objects

The following properties and methods are defined for picture shapes.

class pptx.shapes.picture.Picture[源代码]

A picture shape, one that places an image on a slide.

Based on the p:pic element.

click_action

ActionSetting instance providing access to click behaviors.

Click behaviors are hyperlink-like behaviors including jumping to a hyperlink (web page) or to another slide in the presentation. The click action is that defined on the overall shape, not a run of text within the shape. An ActionSetting object is always returned, even when no click behavior is defined on the shape.

property crop_bottom

float representing relative portion cropped from shape bottom.

Read/write. 1.0 represents 100%. For example, 25% is represented by 0.25. Negative values are valid as are values greater than 1.0.

property crop_left

float representing relative portion cropped from left of shape.

Read/write. 1.0 represents 100%. A negative value extends the side beyond the image boundary.

property crop_right

float representing relative portion cropped from right of shape.

Read/write. 1.0 represents 100%.

property crop_top

float representing relative portion cropped from shape top.

Read/write. 1.0 represents 100%.

property element

lxml element for this shape, e.g. a CT_Shape instance.

Note that manipulating this element improperly can produce an invalid presentation file. Make sure you know what you’re doing if you use this to change the underlying XML.

property has_chart

True if this shape is a graphic frame containing a chart object. False otherwise. When True, the chart object can be accessed using the .chart property.

property has_table

True if this shape is a graphic frame containing a table object. False otherwise. When True, the table object can be accessed using the .table property.

property has_text_frame

True if this shape can contain text.

property height

Read/write. Integer distance between top and bottom extents of shape in EMUs

property is_placeholder

True if this shape is a placeholder. A shape is a placeholder if it has a <p:ph> element.

property left

Read/write. Integer distance of the left edge of this shape from the left edge of the slide, in English Metric Units (EMU)

line

An instance of LineFormat, providing access to the properties of the outline bordering this shape, such as its color and width.

property name

Name of this shape, e.g. ‘Picture 7’

property part

The package part containing this shape.

A BaseSlidePart subclass in this case. Access to a slide part should only be required if you are extending the behavior of python-pptx API objects.

property placeholder_format

A _PlaceholderFormat object providing access to placeholder-specific properties such as placeholder type. Raises ValueError on access if the shape is not a placeholder.

property rotation

Read/write float. Degrees of clockwise rotation. Negative values can be assigned to indicate counter-clockwise rotation, e.g. assigning -45.0 will change setting to 315.0.

shadow

ShadowFormat object providing access to shadow for this shape.

A ShadowFormat object is always returned, even when no shadow is explicitly defined on this shape (i.e. it inherits its shadow behavior).

property shape_id

Read-only positive integer identifying this shape.

The id of a shape is unique among all shapes on a slide.

property top

Read/write. Integer distance of the top edge of this shape from the top edge of the slide, in English Metric Units (EMU)

property width

Read/write. Integer distance between left and right extents of shape in EMUs

property auto_shape_type

Member of MSO_SHAPE indicating masking shape.

A picture can be masked by any of the so-called “auto-shapes” available in PowerPoint, such as an ellipse or triangle. When a picture is masked by a shape, the shape assumes the same dimensions as the picture and the portion of the picture outside the shape boundaries does not appear. Note the default value for a newly-inserted picture is MSO_AUTO_SHAPE_TYPE.RECTANGLE, which performs no cropping because the extents of the rectangle exactly correspond to the extents of the picture.

The available shapes correspond to the members of MSO_AUTO_SHAPE_TYPE.

The return value can also be None, indicating the picture either has no geometry (not expected) or has custom geometry, like a freeform shape. A picture with no geometry will have no visible representation on the slide, although it can be selected. This is because without geometry, there is no “inside-the-shape” for it to appear in.

property image

An Image object providing access to the properties and bytes of the image in this picture shape.

property shape_type

Unique integer identifying the type of this shape, unconditionally MSO_SHAPE_TYPE.PICTURE in this case.

GraphicFrame objects

The following properties and methods are defined for graphic frame shapes. A graphic frame is the shape containing a table, chart, or smart art.

class pptx.shapes.graphfrm.GraphicFrame[源代码]

基类:pptx.shapes.base.BaseShape

Container shape for table, chart, smart art, and media objects.

Corresponds to a <p:graphicFrame> element in the shape tree.

property chart

The Chart object containing the chart in this graphic frame.

Raises ValueError if this graphic frame does not contain a chart.

click_action

ActionSetting instance providing access to click behaviors.

Click behaviors are hyperlink-like behaviors including jumping to a hyperlink (web page) or to another slide in the presentation. The click action is that defined on the overall shape, not a run of text within the shape. An ActionSetting object is always returned, even when no click behavior is defined on the shape.

property element

lxml element for this shape, e.g. a CT_Shape instance.

Note that manipulating this element improperly can produce an invalid presentation file. Make sure you know what you’re doing if you use this to change the underlying XML.

property has_chart

True if this graphic frame contains a chart object. False otherwise.

When True, the chart object can be accessed using the .chart property.

property has_table

True if this graphic frame contains a table object, False otherwise.

When True, the table object can be accessed using the .table property.

property height

Read/write. Integer distance between top and bottom extents of shape in EMUs

property left

Read/write. Integer distance of the left edge of this shape from the left edge of the slide, in English Metric Units (EMU)

property name

Name of this shape, e.g. ‘Picture 7’

property ole_format

Optional _OleFormat object for this graphic-frame shape.

Raises ValueError on a GraphicFrame instance that does not contain an OLE object.

An shape that contains an OLE object will have .shape_type of either EMBEDDED_OLE_OBJECT or LINKED_OLE_OBJECT.

property rotation

Read/write float. Degrees of clockwise rotation. Negative values can be assigned to indicate counter-clockwise rotation, e.g. assigning -45.0 will change setting to 315.0.

property shadow

Unconditionally raises NotImplementedError.

Access to the shadow effect for graphic-frame objects is content-specific (i.e. different for charts, tables, etc.) and has not yet been implemented.

property shape_id

Read-only positive integer identifying this shape.

The id of a shape is unique among all shapes on a slide.

property table

The Table object contained in this graphic frame. Raises ValueError if this graphic frame does not contain a table.

property top

Read/write. Integer distance of the top edge of this shape from the top edge of the slide, in English Metric Units (EMU)

property width

Read/write. Integer distance between left and right extents of shape in EMUs

GroupShape objects

The following properties and methods are defined for group shapes. A group shape acts as a container for other shapes.

Note that:

  • A group shape has no text frame and cannot have one.

  • A group shape cannot have a click action, such as a hyperlink.

class pptx.shapes.group.GroupShape[源代码]

基类:pptx.shapes.base.BaseShape

A shape that acts as a container for other shapes.

property click_action

Unconditionally raises TypeError.

A group shape cannot have a click action or hover action.

property element

lxml element for this shape, e.g. a CT_Shape instance.

Note that manipulating this element improperly can produce an invalid presentation file. Make sure you know what you’re doing if you use this to change the underlying XML.

property has_text_frame

Unconditionally False.

A group shape does not have a textframe and cannot itself contain text. This does not impact the ability of shapes contained by the group to each have their own text.

property height

Read/write. Integer distance between top and bottom extents of shape in EMUs

property left

Read/write. Integer distance of the left edge of this shape from the left edge of the slide, in English Metric Units (EMU)

property name

Name of this shape, e.g. ‘Picture 7’

property part

The package part containing this shape.

A BaseSlidePart subclass in this case. Access to a slide part should only be required if you are extending the behavior of python-pptx API objects.

property rotation

Read/write float. Degrees of clockwise rotation. Negative values can be assigned to indicate counter-clockwise rotation, e.g. assigning -45.0 will change setting to 315.0.

shadow[源代码]

ShadowFormat object representing shadow effect for this group.

A ShadowFormat object is always returned, even when no shadow is explicitly defined on this group shape (i.e. when the group inherits its shadow behavior).

property shape_id

Read-only positive integer identifying this shape.

The id of a shape is unique among all shapes on a slide.

property shape_type

Member of MSO_SHAPE_TYPE identifying the type of this shape.

Unconditionally MSO_SHAPE_TYPE.GROUP in this case

shapes[源代码]

GroupShapes object for this group.

The GroupShapes object provides access to the group’s member shapes and provides methods for adding new ones.

property top

Read/write. Integer distance of the top edge of this shape from the top edge of the slide, in English Metric Units (EMU)

property width

Read/write. Integer distance between left and right extents of shape in EMUs