2017-11-26 1 views
0

kivy에서 간단한 스톱워치를 만들려고하는데 interruptible clock을 사용하여 1/100th 초를 추적하는 간격을 적절히 생성하고 싶습니다 (보통 시계는 충분히 정확하지 않습니다). 그러나 정확하게 interruptible clock을 올바르게 통합하는 방법을 알 수는 없습니다. intteruptible kivy 시계를 사용하는 방법?

나는 그것을 읽어하려하고이

class TimerApp(App): 
    def build_config(self, config): 
     config.setdefaults('section1', { 
      'KIVY_CLOCK': 'interrupt' 
     }) 

    def build(self): 
     config = self.config 
     return AppLayout() 

이 그러나 전혀 Clock.schedule_interval 연료 소모량을 변경하는 것 같지 않았어요 했어요. 이 문제를 해결하는 적절한 방법은 무엇이며 어떻게 설정이 변경되었는지 확인할 수 있습니까?

답변

1

다음 예는 차이를 설명하려고 :

주의 :

from kivy.app import App from kivy.clock import Clock from kivy.uix.boxlayout import BoxLayout import time t = int(round(time.time() * 1000)) #current time in millisecond def call_back(dt): global t t1 = int(round(time.time() * 1000)) print t1 - t t = t1 clock = Clock.schedule_interval(call_back, 1) class TimerApp(App): def build(self): return BoxLayout() if __name__ == '__main__': TimerApp().run() 
: 나는 기본 설정은이 테스트

1의 (1000 밀리 초)에 제한 시간을 설정

출력은 다음과 같습니다.

1002 
1003 
1006 
1004 
1006 
1005 
1004 
1001 
1003 
1002 
1003 

당신은 출력이 항상 볼 수있는 (거의)> 1000 밀리 초

interrup의 설정으로 :

... 
from kivy.config import Config 

... 
class TimerApp(App): 

    def build(self): 
     Config.set('graphics', 'KIVY_CLOCK', 'interrupt') 
     Config.write() 
     return BoxLayout() 
... 

과 출력 :

997 
998 
1000 
1000 
998 
998 
1000 
1001 
1000