kivy/python 按计划更新标签
kivy/python update label by a schedule
我尝试使用
不断更新标签的文本
Clock.schedule_interval.
在此示例中,我收到以下错误消息:
NameError: 全局名称 'radio_station' 未定义
我也不知道为什么。有人可以帮我吗?
非常感谢。
kv-文件:
<CtrlRadio>:
radio_station: stationName
BoxLayout:
orientation: "vertical"
Label:
id: stationName
text:"default text"
python 文件:
class CtrlRadio(Widget):
radio_station = StringProperty()
def print_info_to_display(self):
radio_station.text = "Radio Station"
# start scheduling - 500ms
Clock.schedule_interval(print_info_to_display, 0.5)
class RadioApp(App):
def build(self):
return CtrlRadio()
if __name__ == '__main__':
RadioApp().run()
radio_station.text = "Radio Station"
将radio_station
替换为self.radio_station
。
我尝试使用
不断更新标签的文本Clock.schedule_interval.
在此示例中,我收到以下错误消息:
NameError: 全局名称 'radio_station' 未定义
我也不知道为什么。有人可以帮我吗?
非常感谢。
kv-文件:
<CtrlRadio>:
radio_station: stationName
BoxLayout:
orientation: "vertical"
Label:
id: stationName
text:"default text"
python 文件:
class CtrlRadio(Widget):
radio_station = StringProperty()
def print_info_to_display(self):
radio_station.text = "Radio Station"
# start scheduling - 500ms
Clock.schedule_interval(print_info_to_display, 0.5)
class RadioApp(App):
def build(self):
return CtrlRadio()
if __name__ == '__main__':
RadioApp().run()
radio_station.text = "Radio Station"
将radio_station
替换为self.radio_station
。