如何使用Python-PPTX填充文本框背景颜色?
我正在使用Python-PPTX创建PPT,我想用其他颜色填充文本框背景。
from pptx import Presentation
from pptx.util import Inches, Pt
from datetime import datetime
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
prs = Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
slide_layout = prs.slide_layouts[5]
slide2 = prs.slides.add_slide(slide_layout)
title_textbox = slide.shapes.add_textbox(Inches(5), Inches(0.4), Inches(6), Inches(0.6))
title = title_textbox.text_frame
pic = slide.shapes.add_picture('image_name.jpg', Inches(3.8), Inches(1.3), Inches(8.5), Inches(6))
subtitle_textbox = slide.shapes.add_textbox(Inches(5), Inches(7.5), Inches(6), Inches(1))
subtitle = subtitle_textbox.text_frame
I am using Python-pptx to create ppt, i want to fill the textbox background with other color.
from pptx import Presentation
from pptx.util import Inches, Pt
from datetime import datetime
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
prs = Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
slide_layout = prs.slide_layouts[5]
slide2 = prs.slides.add_slide(slide_layout)
title_textbox = slide.shapes.add_textbox(Inches(5), Inches(0.4), Inches(6), Inches(0.6))
title = title_textbox.text_frame
pic = slide.shapes.add_picture('image_name.jpg', Inches(3.8), Inches(1.3), Inches(8.5), Inches(6))
subtitle_textbox = slide.shapes.add_textbox(Inches(5), Inches(7.5), Inches(6), Inches(1))
subtitle = subtitle_textbox.text_frame
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是100%确定我是否正确收到您的问题。您想创建一个文本框并上色吗?
我对它进行了一些更改:
这将创建一个带有文本“ foo”和“红色”的文本框。您可以找到更多可以操纵形状的选项在这里。
I am not 100% sure if I got your question correctly. You want to create a textbox and color it?
I changed it a bit:
This creates a textbox with text "foo" and red color. You can find more options for the manipulation of your shape here.