Kivy:返回动画 gif,然后调用另一个 def
Kivy: returning animated gif and then calling another def
单击按钮后,应用程序应该会显示一个非常重的 table,所以我想先显示一个动画 gif
,然后再显示 table。
单击按钮时,会调用第一个 def:
wait_image= Loading()
self.add_widget(wait_image)
Clock.schedule_once(lambda x: self.DisplayTable(self), 0)
但这只会加载动画的第一帧 gif
。如果我将 Clock.schedule
替换为 return self
,则动画 gif 可以工作,但不会调用 DisplayTable
def:
wait_image= Loading()
self.add_widget(wait_image)
return self
我试图调用另一个将 return 自身的 def,然后继续 DisplayTable
但这也不起作用(.gif 不是动画但 table 显示):
Loading_image(self)
Clock.schedule_once(lambda x: self.DisplayTable(self), 0)
与 :
def Loading_image(self):
wait_image= Loading()
self.add_widget(wait_image)
return self
那么我如何通过简单的点击调用并显示动画 gif,然后继续调用 DisplayTable def?
这里是 Builder
和 Loading
class:
Builder.load_string('''
<Loading>
source : 'loading.zip'
anim_delay : 0.02
allow_stretch : True
keep_ratio : True
keep_data : True
''')
class Loading(AsyncImage):
pass
密码是here
您需要让事件循环时间来更新您的 gif...使用 kivyoav 使其变得简单:
from kivyoav.delayed import delayable
@delayable
def DisplayTable(self):
for i in ROWS:
yield 0.01 # after each row the gif will have time to update ...
for j in COLS:
pass # build your table cols ...
另一种选择是在不同的线程中完成繁重的工作,稍后仅使用 Clock.schedule_once
更新 UI
def build_table():
...
#stuff that take time
stuff = ...
...
Clock.schedule_once(lambda dt: build_ui_table(stuff)) #since you can use the UI only from the main thread
threading.Thread(target=build_table).start()
单击按钮后,应用程序应该会显示一个非常重的 table,所以我想先显示一个动画 gif
,然后再显示 table。
单击按钮时,会调用第一个 def:
wait_image= Loading()
self.add_widget(wait_image)
Clock.schedule_once(lambda x: self.DisplayTable(self), 0)
但这只会加载动画的第一帧 gif
。如果我将 Clock.schedule
替换为 return self
,则动画 gif 可以工作,但不会调用 DisplayTable
def:
wait_image= Loading()
self.add_widget(wait_image)
return self
我试图调用另一个将 return 自身的 def,然后继续 DisplayTable
但这也不起作用(.gif 不是动画但 table 显示):
Loading_image(self)
Clock.schedule_once(lambda x: self.DisplayTable(self), 0)
与 :
def Loading_image(self):
wait_image= Loading()
self.add_widget(wait_image)
return self
那么我如何通过简单的点击调用并显示动画 gif,然后继续调用 DisplayTable def?
这里是 Builder
和 Loading
class:
Builder.load_string('''
<Loading>
source : 'loading.zip'
anim_delay : 0.02
allow_stretch : True
keep_ratio : True
keep_data : True
''')
class Loading(AsyncImage):
pass
密码是here
您需要让事件循环时间来更新您的 gif...使用 kivyoav 使其变得简单:
from kivyoav.delayed import delayable
@delayable
def DisplayTable(self):
for i in ROWS:
yield 0.01 # after each row the gif will have time to update ...
for j in COLS:
pass # build your table cols ...
另一种选择是在不同的线程中完成繁重的工作,稍后仅使用 Clock.schedule_once
更新 UIdef build_table():
...
#stuff that take time
stuff = ...
...
Clock.schedule_once(lambda dt: build_ui_table(stuff)) #since you can use the UI only from the main thread
threading.Thread(target=build_table).start()