10

threading in kivy example

 2 years ago
source link: https://gist.github.com/el3/3c8d4e127d41e86ca3f2eae94c25c15f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

threading in kivy example · GitHub

Instantly share code, notes, and snippets.

threading in kivy example

from kivy.app import App from kivy.lang import Builder from kivy.uix.boxlayout import BoxLayout from kivy.properties import StringProperty from kivy.clock import mainthread

import threading import time

class MyBL(BoxLayout): counter = 0 data_label = StringProperty("Nothing yet!")

def __init__(self, **kwargs): super().__init__(**kwargs) threading.Thread(target=self.get_data).start()

def get_data(self): while App.get_running_app(): # get data here # sock.recv(1024) or how you do it time.sleep(1)

# if you change the UI you need to do it on main thread self.set_data_label(self.counter)

self.counter += 1

@mainthread def set_data_label(self, data): self.data_label = str(data)

KV = """ MyBL: Label: font_size: "30sp" text: "Some Data" Label: font_size: "30sp" text: root.data_label """

class MyApp(App): def build(self): return Builder.load_string(KV)

MyApp().run()


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK