繁体   English   中英

这种说法从何而来?

[英]Where does this argument come from?

编辑:显然我不是很清楚。 我真的不知道发生了什么,所以我不知道具体要求什么。 我的问题是小睡如何得到它的论据,而我没有具体说明。 Inclement明白我的意思,所以我想现在已经回答了。

这可能是愚蠢的,但我真的不明白更新(在“更新”中)的“小睡”参数从何而来。 编辑:(它从哪里获得它的价值,这就是我的意思)。

“更新”仅从“ on_start”调用(编辑:通过),在其他任何地方都不会调用。

class ClockApp(App):
    sw_started = False
    sw_seconds = 0

    def on_start(self):
        Clock.schedule_interval(self.update, 0)

    def update(self, nap):
        if self.sw_started:
            self.sw_seconds += nap

        self.root.ids.time.text = strftime('[b]%H[/b]:%M:%S')

        m, s = divmod(self.sw_seconds, 60)
        self.root.ids.stopwatch.text = (u'{0:02d}:{1:02d}.[size=40]{2:02d}[/size]'
                                        .format(int(m), int(s), int(s * 100 % 100)))

    def start_stop(self):
        self.root.ids.start_stop.text = 'Start' if self.sw_started else 'Stop'
        self.sw_started = not self.sw_started

    def reset(self):
        if self.sw_started:
            self.root.ids.start_stop.text = 'Start'
            self.sw_started = False

        self.sw_seconds = 0

update不是直接调用的,而是通过Clock.schedule_interval(self.update, 0)与Clock Clock.schedule_interval(self.update, 0)调度的。 这会将参数自上次调用以来的时间自动传递给该函数,在此示例中此时间称为nap

由于两次调用之间的时间设置为0 ,因此每帧将调用一次该函数,并且nap最终应约为1/60。

为了进行比较,如果将其更改为Clock.schedule_interval(self.update, 1) ,您会发现由于小(或如果主线程被阻塞,大), nap总是大约为1 ...但不完全为1。推框时的波动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM