Python 3.x PPTX找不到placehold

2024-09-24 06:32:26 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我的代码是:

from pptx import Presentation

prs = Presentation('template.pptx')

title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]

title.text = "Python 3.6 - Turtle Race"
subtitle.text = "Data Analytics&Visualization with random generated data"


for placeholder in prs.slide_layouts[4].placeholders:
    print('%d %s' % (placeholder.placeholder_format.idx, placeholder.name))

slide = prs.slides.add_slide(prs.slide_layouts[4])
littleTitle = slide.placeholders[1]

littleTitle.text('Comparison of Winning times and pieces of wins')

prs.save("visualiztaion.pptx")

我的输出是(有错误):

0 Title 1
1 Text Placeholder 2
2 Content Placeholder 3
3 Text Placeholder 4
4 Content Placeholder 5
10 Date Placeholder 6
11 Footer Placeholder 7
12 Slide Number Placeholder 8
Traceback (most recent call last):
  File "D:/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_!Piton/turtleRace/presentationMaker.py", line 34, in <module>
    littleTitle.text('Comparison of Winning times and pieces of wins')
TypeError: 'str' object is not callable

Process finished with exit code 1

Image of my project

你可以看到我在项目中的每一个建议文件,如果你想我可以发送我的项目解释器的图片

所以我的问题基本上就是如何将文本插入0 Title 11 Text Placeholder 2

所以我主要是想解决并传递错误,因为我必须让代码正常工作

所以请帮帮我


Tags: of代码texttitlepresentationplaceholderlayoutslayout