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)
計數器應該更新,除非時鐘正在做一些奇怪的。你可以通過在你的'example'函數內執行'print self.counter'來確保它實際上不會更新嗎? – Victory
您是否在通過'from pyglet import app'調用'app.run()'應用程序? –
我已經在示例方法中完成了打印self.counter,並且它每3秒打印一次「0」。我認爲所有與時鐘相關的東西都能正常工作,因爲它每3秒打印一次。 – david