【发布时间】:2021-12-31 10:22:38
【问题描述】:
我正在为应用程序制作加载屏幕,但在同时运行动画和算法(需要很长时间才能运行)时遇到了一点问题。但是,当我运行该代码块时,当我尝试调用“self.ids.loading_anim”时,出现错误 AttributeError: 'super' object has no attribute 'getattr'。任何人都可以推荐一种更好的方法来在 kivy 中多线程动画吗?请记住,当我对其他算法进行多线程处理时,运行时间太长。
Python 代码:
def animate_image(self):
anim = Animation()
anim.start(self.ids.loading_anim)
class LoadingWindow(Screen):
def on_enter(self):
t = Thread(target=animate_image, args=(self))
t.deamon = True
t.start()
for x in range(5):
print(x) # this is just a test algorithm which takes 5 seconds to run
time.sleep(1) # in the real file there is another algorithm which takes time to run
基维代码
<LoadingWindow>
FloatLayout:
Image:
id: animation
source: 'loading.gif'
size_hint_x:0.6
size_hint_y:0.6
pos_hint: {'x':0.19, 'y':0.2}
allow_stretch: True
anim_delay: 0
anim_reset: True
Label:
text: 'Searching the internet for recipes....'
pos_hint: {'x':0, 'y':0.3}
font_size: 28
【问题讨论】:
-
请提取minimal reproducible example。我有一半确定这个错误不是多线程或 kivy 所特有的,这将决定。
标签: python multithreading kivy