1
以下是我正在使用的基本示例。該標籤顯示爲我所期望的,但文本從未更改,即使我看到控制檯中的打印語句顯示Clock.schedule_interval爲,其間距爲。任何想法,以什麼已經出錯?試圖更改Kivy中的標籤文本,它永遠不會更改
謝謝你,新年快樂!
首先.kvlang文件
<Demo>:
button_text: my_button
BoxLayout:
Label:
id: my_button
text: 'Initial Text!'
而且我的Python。
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty, StringProperty
from kivy.clock import Clock
import random
class Demo(BoxLayout):
button_text = ObjectProperty
def change_text(self, dt):
self.button_text.text = str(random.randint(1, 10))
print('Should have changed button text to {}'.format(self.button_text.text))
def start(self):
Clock.schedule_interval(self.change_text, 10)
class TutorialApp(App):
def build(self):
foo = Demo()
foo.start()
return Demo()
if __name__ == "__main__":
TutorialApp().run()
而你是正確的:)愚蠢錯過對象創建的開始!謝謝您的幫助 – Craig