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/