如何在运行时获取当前时间戳

How to get current timestamp in runtime

有如下三种说法:

print("first time", time.time())
self.wait(5)
print("second time", time.time())

我想"second time"和"first time"应该相差5秒,但是它们是一样的,为什么?

我认为 self.wait(5) 应该是异步调用,如果是这样,如何在运行时获取时间戳?

如果您想要在终端中打印动画每个时刻的确切秒数,您可以这样做(时间保存在变量 self.time 中):

class TimeTest(Scene):
    def print_time(self):
        print("Time:",self.time)

    def construct(self):
        dot=Dot()
        # 0 seconds
        self.print_time()
        self.play(Write(dot,run_time=2))
        # 2 seconds
        self.print_time()
        self.wait()
        # 3 seconds
        self.print_time()
        self.play(dot.shift,UP,run_time=1)
        # 4 seconds
        self.print_time()
        self.play(FadeToColor(dot,RED,run_time=3))
        # 7 seconds
        self.print_time()
        self.wait()
        # 8 seconds
        self.print_time()