Kivy Splash Screen image with fade in effect

为君一笑 提交于 2019-12-11 04:15:31

问题


I would like to know how to make a splash screen with kivy and display a picture in fade in for few seconds.

The best i can do was with this code:

class MyApp(App):

    def __init__(self, **kwargs):
        super(MyApp, self).__init__(**kwargs)
        self.splash_screen_image = Image(source='images/pyrat_icon.png', size=(0, 0))
        Clock.schedule_once(self.start_anim, .01)

    def build(self):
        self.main_widget = MainWidget()
        return self.main_widget

    def start_anim(self, dt):
        self.splash_screen_image.pos = (self.main_widget.center_x, self.main_widget.center_y)
        self.main_widget.add_widget(self.splash_screen_image)
        animation = Animation(x=self.main_widget.center_x - 35, y=self.main_widget.center_y - 35, height=70, width=70, d=2,
                              t='in_quad')
        animation.start(self.splash_screen_image)
        Clock.schedule_once(self.end_anim, 3)

    def end_anim(self, dt):
        self.main_widget.remove_widget(self.splash_screen_image)

This display my logo on the screen and it disappear after 3 seconds but it wait for the app to start so when the app is loading there is only a black window.


回答1:


Android/iOS:

Splashscreen is used by default on python-for-android (presplash), there you can set whatever image you like. Don't know how does it work on ios, but I think there is splashscreen too.


Windows/Linux/Mac/RPi:

No such thing exists on these. Maybe you can set something with PyInstaller when packaging for the OS, otherwise you'd need to make it yourself. I can recommend you using ScreenManager and its Transitions combined with Clock or maybe even Animation - depends on what wou want that image to do. Example

To set a length of a transition look here, which should be accessible within transitions e.g. FadeTransition(duration=1.5)



来源:https://stackoverflow.com/questions/37165912/kivy-splash-screen-image-with-fade-in-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!