python - 如何在 Manim 社区中将文本放在矩形内

标签 python python-3.x animation manim algorithm-animation

this is the thing I wanted to make

我是 manim 的新手,我正在尝试将文本放在一个矩形内,如图中所示 我怎样才能做到这一点 ?? :(

最佳答案

您可以使用 VGroup 将框和文本组合在一起。

示例代码:

from manimlib import *

def create_textbox(color, string):
    result = VGroup() # create a VGroup
    box = Rectangle(  # create a box
        height=2, width=3, fill_color=color, 
        fill_opacity=0.5, stroke_color=color
    )
    text = Text(string).move_to(box.get_center()) # create text
    result.add(box, text) # add both objects to the VGroup
    return result


class TextBox(Scene):  
    def construct(self):

        # create text box
        textbox = create_textbox(color=BLUE, string="Hello world")
        self.add(textbox)

        # move text box around
        self.play(textbox.animate.shift(2*RIGHT), run_time=3)
        self.play(textbox.animate.shift(2*UP), run_time=3)
        self.wait()

关于python - 如何在 Manim 社区中将文本放在矩形内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70142914/

相关文章:

python - tfidfvectorizer 根据所有单词打印结果

python 3.4 tkinter frame 不填充垂直方向

python - 生成自定义 pyunit 报告

python - Kivy:用 Canvas 制作动画图像的正确方法是什么?

iphone - 如何进行抛物线转换?

python - 在 Django 模型表单中覆盖 clean() 方法时返回 cleaned_data

python - 名称 'DataFrameSelector' 未定义

mysql - 插入多行时 commit() 的最佳实践

python - 使用 pytest mocker 忽略assert_has_calls中的链式调用

列表框项目上的 WPF 动画