Reputation: 25
I'm trying to create a "SplashScreen" with python and kivy. The idea is to start the program, show the SplashScreen as fast as possible, run some methods in background, then automatically switch to the "MainScreen". Thats the first moment where user input is possible and expected.
The problem is, that every way I tried, I got following result: Program starts running, shows a blank white window, runs my methods, shows the SplashScreen, immediately switches to MainScreen.
I simply don't get how to force kivy show the SplashScreen before running the methods I want. To clearify that: "SplashScreen" does not mean anthing fancy like transparency or stuff. Just another standard screen.
Here is my Code:
mainWindow.py
Builder.load_file("loadingscreen.kv")
Builder.load_file("mainscreen.kv")
class LoadingScreen(Screen):
pass
class MainScreen(Screen):
pass
class FaitApp(App):
LoadingStartUp = None
def build(self):
self.root = ScreenManager()
self.root.add_widget(LoadingScreen(name='LoadingScreen'))
self.root.add_widget(MainScreen(name='MainScreen'))
return self.root
def on_start(self):
self.LoadingStartUp = LoadingStartUp(self)
Clock.schedule_once(self.LoadingStartUp.loadButtonImages,0)
return
if __name__ == '__main__':
app = FaitApp()
app.run()
sys.exit()
loadingscreen.kv
#kivy 1.10.1
<LoadingScreen>:
canvas:
Color:
rgba: 1, 1 , 0, 1
Rectangle:
size: self.size
Label:
font_size: 42
text: root.name
mainscreen.kv
#kivy 1.10.1
<MainScreen>:
canvas:
Color:
rgba: 1, 1 , 0, 1
Rectangle:
size: self.size
Label:
font_size: 42
text: root.name
loadingStartUp.py
class LoadingStartUp(object):
app = None
def __init__(self, app):
self.app = app
return
def loadButtonImages(self):
log.debug('LoadingStartUp')
log.debug('Waiting for everything ready!')
sleep(5)
self.app.root.current = 'MainScreen'
return
I also tried to use Clock.schedule_once()
within build()
and on_start()
. I even tried to load the sites without ScreenManager with self.root = Builder.load_file()
. The result was the same every time as described above.
It would be enought I think to detect when the SplashScreen is correctly shown on screen and run a method after that.
Any solutions/hints/tipps/advices are very appreciated! Thanks!
Upvotes: 1
Views: 3487
Reputation: 38937
I think you can get what you want by eliminating the sleep(5)
from the loadButtonImages()
method and modify the Clock.schedule_once(self.LoadingStartUp.loadButtonImages,0)
call to Clock.schedule_once(self.LoadingStartUp.loadButtonImages,5)
. The sleep()
call prevents the GUI from doing anything during those 5 seconds. And the 5
in the Clock.schedule_once()
call prevents the main screen from showing for 5 seconds.
Upvotes: 1