Kivy Widget Clock interval updating

Viewed 34

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() 
'
1 Answers

You haven't added anything to FirstLayout. Add it like,

class FirstLayout(GridLayout):
    r = 0

    def __init__(self, **kwargs):
        ...
        layout.add_widget(self.change)
        self.cols = 1 # say.
        self.add_widget(layout)
Related