2

I am trying to move the text box with the title from the center to the top of the slide deck. I am not able to find the right parameters for my script. Here are some lines that relate to it:

#setting slide type "Title and Content"
title_only_layout = pptx.slide_layouts[1]

#Adding content into the title box
pptx.slides.add_slide(title_only_layout)
pptx.slides[idx].shapes.title.text = "I am a title!"

These commands add the title box in the center of the deck. How do I adjust this script?

LaLaTi
  • 1,455
  • 3
  • 18
  • 31
  • Hi, I'm not entirely sure what you mean with "Cm" syntax, do you mean centimeters from a given position here? – Tim.Lucas Nov 20 '19 at 20:03
  • Anyhow, looking at the documentation, it seems your title is a `placeholder` object, and these have properties that can be accessed and changed it seems, see https://python-pptx.readthedocs.io/en/latest/user/placeholders-using.html#identify-and-characterize-a-placeholder and https://python-pptx.readthedocs.io/en/latest/api/shapes.html#pptx.shapes.base.BaseShape.placeholder_format . Have you tried to use those? – Tim.Lucas Nov 20 '19 at 20:10
  • @Tim.Lucas Cm indeed is for centimenter but I am open to better ways of course. I checked the link but I am not sure which object the right one is. Can you assist? – LaLaTi Nov 20 '19 at 22:50

1 Answers1

5

As Tim.Lucas mentions, a slide title is a placeholder, which is a shape like any other in that it has .left, .top, .width, and .height attributes which you can set to position and size the object.

from pptx.util import Cm

title = slide.shapes.title
title.top = Cm(3)
# ... and likewise for other position and size attributes
scanny
  • 26,423
  • 5
  • 54
  • 80