Kivy Widget 时钟间隔更新
我遇到的问题是,Clock.interval 在输出上打印,但不在小部件屏幕上打印,因此时钟间隔正在工作,但是我不明白为什么更新没有在屏幕上输出,请帮助。
'
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
class FirstLayout(GridLayout):
r = 0
def __init__(self, **kwargs):
super(FirstLayout, self).__init__(**kwargs)
layout = GridLayout(cols = 2)
#self.change = self.ids.temp_label
self.change = Label(text = "something")
layout.add_widget(self.change)
def my_callback(self, *args):
self.r += 1
print(self.r)
t = str(self.r)
self.change.text = t
return self.change
class MainApp(App):
def build(self):
first_layout = FirstLayout()
Clock.schedule_interval(first_layout.my_callback,2)
return first_layout
if __name__ == '__main__':
MainApp().run()
'
I have problem that , the Clock.interval is printing on the output but not on the Widget screen, So the clock interval is working however I can't get it why the update is not outputting on the screen, please help.
'
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
class FirstLayout(GridLayout):
r = 0
def __init__(self, **kwargs):
super(FirstLayout, self).__init__(**kwargs)
layout = GridLayout(cols = 2)
#self.change = self.ids.temp_label
self.change = Label(text = "something")
layout.add_widget(self.change)
def my_callback(self, *args):
self.r += 1
print(self.r)
t = str(self.r)
self.change.text = t
return self.change
class MainApp(App):
def build(self):
first_layout = FirstLayout()
Clock.schedule_interval(first_layout.my_callback,2)
return first_layout
if __name__ == '__main__':
MainApp().run()
'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未向
FirstLayout
添加任何内容。添加它就像,You haven't added anything to
FirstLayout
. Add it like,