[英]kivy, How to display the value(StringProperty) in multithreading by python
我想显示该值是由kivy通过多线程创建的。 该值是由其他类中的多线程过程创建的。 我想在root_class中显示值。
详细信息:多线程过程在调用Aaa()中。 类Aaa()中的多线程调用的方法在类Ddd()中。 用奇异的语言不能显示进程运行中的值?
python代码
class Aaa(BoxLayout):
def multithread(self):
ddd = Ddd()
thread1 = threading.Thread(target=ddd.eee,args=())
thread1.start()
class Ddd(BoxLayout):
ff=StringProperty()
def eee(self):
self.e = 0
for _ in range(10):
self.e += 1
self.f = self.e * 2
self.ff = str(self.f)
time.sleep(3)
class WwwApp(App):
def build(self):
return Aaa()
if __name__ == '__main__':
WwwApp().run()
奇异码
<Aaa>:
id: aaa
size: 500,500
orientation: 'vertical'
Button:
id: button_b
text: 'exec_root.multithread()'
size_hint_y: 0.5
on_press: root.multithread()
Ddd:
size_hint_y: 0.5
<Ddd>:
id: ddd
size: 500,200
Label:
id: label_d
text: root.ff
谢谢您的指导!
你kivy代码创建的实例Ddd
为孩子Aaa
。 然后,您的multithread
方法将创建Ddd
另一个实例并运行该新实例的eee
,因此显示中的Ddd
对此一无所知。 您需要运行已经创建的Ddd
实例的eee
方法。 使用ID进行检索。
因此,将multithreaad
方法中的ddd = self.ids.ddd
ddd = Ddd()
替换为ddd = self.ids.ddd
。 另外,您还需要按照下面的顺序在id代码中移动ID:
<Aaa>:
id: aaa
size: 500,500
orientation: 'vertical'
Button:
id: button_b
text: 'exec_root.multithread()'
size_hint_y: 0.5
on_press: root.multithread()
Ddd:
id: ddd
size_hint_y: 0.5
<Ddd>:
size: 500,200
Label:
id: label_d
text: root.ff
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.