小编use*_*089的帖子

Kivy 和 Python 线程 - 如何在它们之间获取数据

我在使用 python(threading) 和 kivy 时遇到了一些问题:

这是一些代码:

import kivy
import threading 
import time
from kivy.app import App
from kivy.uix.button import Button

class Thread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)  
        self.counter = 0        
    def run(self):
        while True:
            print "Thread is running "+str(self.counter)
            app.button.text = self.set_button(self.counter)
            app.button.text = str(self.counter)
            time.sleep(0.5)
    def count(self):
        self.counter += 1
        app.button.text = str(self.counter)     
    def set_button(self, value):
        app.button.text = str(value)

class MyApp(App):
    def __init__ (self, thread_object):
        App.__init__(self) 
        self.thread_object = thread_object      
    def callback(self,instance):
        print('The button <%s> is being pressed' % instance.text)
        self.thread_object.count()
    def …
Run Code Online (Sandbox Code Playgroud)

python multithreading kivy

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

kivy ×1

multithreading ×1

python ×1