这个论点从何而来?
Where does this argument come from?
编辑:显然我不是很清楚。我真的不知道发生了什么,所以我不知道具体要问什么。我的问题是 nap 如何获得它的论点,而我没有指定一个。 Inclement明白我的意思,所以我想现在已经回答了。
这可能很愚蠢,但我真的不明白更新的 "nap" 参数(在 "update" 中)从何而来。编辑:(我的意思是它从哪里获得价值)。
"Update" 仅从(编辑:通过)"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一起调度的。这会自动将参数传递给与上次调用后的时间相对应的函数,在本例中称为 nap
。
由于调用之间的时间设置为 0
,该函数将每帧调用一次,nap
最终应该约为 1/60。
为了比较,如果你把它改成Clock.schedule_interval(self.update, 1)
,你会发现nap
总是大约为1...但不完全是1,由于小(或者如果主线程是阻塞,大)帧被推送时的波动。
编辑:显然我不是很清楚。我真的不知道发生了什么,所以我不知道具体要问什么。我的问题是 nap 如何获得它的论点,而我没有指定一个。 Inclement明白我的意思,所以我想现在已经回答了。
这可能很愚蠢,但我真的不明白更新的 "nap" 参数(在 "update" 中)从何而来。编辑:(我的意思是它从哪里获得价值)。
"Update" 仅从(编辑:通过)"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一起调度的。这会自动将参数传递给与上次调用后的时间相对应的函数,在本例中称为 nap
。
由于调用之间的时间设置为 0
,该函数将每帧调用一次,nap
最终应该约为 1/60。
为了比较,如果你把它改成Clock.schedule_interval(self.update, 1)
,你会发现nap
总是大约为1...但不完全是1,由于小(或者如果主线程是阻塞,大)帧被推送时的波动。