Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

popup - kivy Python: animated picture while waiting Login Password check code

I need to open popup window when I check the Login Password. I will put the Login Password code in the place of time code after that. But even with time code, I can't open the animated Gif and after 10s the window is closed automatically. This is my code

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.uix.gridlayout import GridLayout
import time
kv = """
<Test@AnchorLayout>:
    AsyncImage:
        source: 'wait.gif'
        anim_delay: 0.1
Test:"""



class TestApp(App):

    def build(self):
        layout = GridLayout(cols=1, padding=10)
        anim = Builder.load_string(kv)
        layout.add_widget(anim)
        popup = Popup(content=layout)  
        popup.open()  
        print('Hello world')
        now = time.time()
        future = now + 10
        while time.time() < future:
        popup.dismiss()
        

if __name__ == '__main__':
    TestApp().run()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

here is another answer which works perfectly:

from kivy.clock import Clock
#rest of the code above
    def build(self):
            layout = GridLayout(cols=1, padding=10)

            anim = Builder.load_string(kv)
            layout.add_widget(anim)
            popup = Popup(content=layout)
            popup.open()
            print('Hello world')
Clock.schedule_once(App().get_running_app().stop,10)#....rest of the code below

u can use the clock feature. idk why i forgot it lol ;D


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...