2014-03-30 27 views
0

我知道這可能是一個非常愚蠢的錯誤,但我試圖在調用示例的init方法中向計數器中添加+1。我注意到櫃檯停留在0,但我不確定我在這裏做錯了什麼。爲什麼我無法將+1加到這個櫃檯?

class newlabel(Label): 
    def __init__(self, **kwargs): 
     super(newlabel, self).__init__(**kwargs) 
     self.font_name='PressStart2P.ttf' 
     self.markup = True 
     self.counter=0 
     self.words = self.text.split(' ') 

    def example(self, *args): 
     self.counter += 1 
     words = self.text.split(' ') 
     if len(self.words) >= self.counter: 
      self.text = hello[self.counter] 
     anim = Animation(size_hint=(1, .27), duration=1.7) 
     anim.start(view) 

newmessage = newlabel(text = "this is a test hello") 
Clock.schedule_interval(newmessage.example, 3) 
+0

計數器應該更新,除非時鐘正在做一些奇怪的。你可以通過在你的'example'函數內執行'print self.counter'來確保它實際上不會更新嗎? – Victory

+0

您是否在通過'from pyglet import app'調用'app.run()'應用程序? –

+0

我已經在示例方法中完成了打印self.counter,並且它每3秒打印一次「0」。我認爲所有與時鐘相關的東西都能正常工作,因爲它每3秒打印一次。 – david

回答

1

好的問題解決了。問題是我有一個重複的行。

self.words = self.text.split(' ') 

正確一個在INIT之中,並且我不小心也有它的示例性方法將其使它分裂的話,每次例如被調用。

0

的問題是

newmessage.example 

實際調用該函數必須是

Clock.schedule_interval(newmessage.example(), 3) 
相關問題