如何使用 pptx-python 库更改标题位置?

LaL*_*aTi 3 python python-pptx

我正在尝试将带有标题的文本框从幻灯片的中心移动到顶部。我无法找到适合我的脚本的正确参数。以下是一些与之相关的行:

#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!"
Run Code Online (Sandbox Code Playgroud)

这些命令将标题框添加到卡片组的中央。我该如何调整这个脚本?

sca*_*nny 6

正如 Tim.Lucas 提到的,幻灯片标题是一个占位符,它的形状与其他形状一样,具有.left、.top、.width和 。height您可以设置用于定位和调整对象大小的属性。

from pptx.util import Cm

title = slide.shapes.title
title.top = Cm(3)
# ... and likewise for other position and size attributes
Run Code Online (Sandbox Code Playgroud)