Altering a kivy property from another thread

后端 未结 2 2059
面向向阳花
面向向阳花 2020-12-10 16:08

I\'m experimenting with some kivy code. I tried modifing a kivy property(text_colour) from a tread created with threading lib. Program works fine but the thread

2条回答
  •  执笔经年
    2020-12-10 16:44

    It works for me:

    from kivy.app import App
    from kivy.uix.label import Label
    import threading
    
    import time
    
    class ScatterTextWidget(Label):
    
        def __init__(self,**kwargs):
        self.text = 'nima'
        self.color = [0, 1, 1, 1]
        super(ScatterTextWidget, self).__init__(**kwargs)
    a = ScatterTextWidget()
    def zaaa():
        import time
        time.sleep(3)
        a.color = [0, 0, 1, 1]
        print "function ran"   
    
    t = threading.Thread(target= zaaa)
    t.start()
    
    class TataApp(App):
        def build(self):
            return a
    
    
    if __name__ == "__main__":
        TataApp().run()
    

提交回复
热议问题