python - Print and clear output on screen with Kivy -
i'm trying print words on screen kivy. i'm looking print first word sleep 2 seconds clear first word , print second word
what i'm doing:
from kivy.app import app kivy.uix.label import label kivy.uix.gridlayout import gridlayout random import choice time import sleep xwords = ["hello1", "hello2", "hello3", "hello4", "hello5"] class test(gridlayout): def __init__(self, **kwargs): super(test, self).__init__(**kwargs) self.cols = 1 x in xrange(2): # want show frist word sleep 2 sec clear first word screen print second word self.add_widget(label(text = "[b]"+choice(xwords)+"[/b]", markup = true, font_size = "40sp")) sleep(2) # clear words in screen x in xrange(5): # show new 4 words self.add_widget(label(text = "[b]"+choice(xwords)+"[/b]", markup = true, font_size = "40sp")) class testapp(app): def build(self): return test() if __name__ == "__main__": testapp().run() how can this?
don't use time.sleep, blocks gui because whole function doesn't return until time.sleep does.
use clock.schedule_once instead. below simple example call function called update in 2 seconds, can whatever want within function including scheduling one.
from kivy.clock import clock class test(gridlayout): def __init__(self, **kwargs): super(test, self).__init__(**kwargs) clock.schedule_once(self.update, 2) # 2 2 seconds def update(self, *args): self.clear_widgets() # add more widgets here
Comments
Post a Comment