具有淡入淡出效果的 Kivy 启动画面图像
Kivy Splash Screen image with fade in effect
我想知道如何用kivy制作启动画面并淡入显示几秒钟的图片。
我能做的最好的就是使用这段代码:
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)
这会在屏幕上显示我的徽标并在 3 秒后消失,但它会等待应用程序启动,因此当应用程序加载时只有黑色 window。
Android/iOS:
Splashscreen 在 python-for-android (presplash) 上默认使用,在那里你可以设置任何你喜欢的图像。不知道它在 ios 上如何工作,但我认为也有闪屏。
Windows/Linux/Mac/RPi:
这些上不存在这样的东西。也许你可以用 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
设置一些东西
设置过渡外观的长度 here,应该可以在过渡中访问,例如FadeTransition(duration=1.5)
我想知道如何用kivy制作启动画面并淡入显示几秒钟的图片。
我能做的最好的就是使用这段代码:
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)
这会在屏幕上显示我的徽标并在 3 秒后消失,但它会等待应用程序启动,因此当应用程序加载时只有黑色 window。
Android/iOS:
Splashscreen 在 python-for-android (presplash) 上默认使用,在那里你可以设置任何你喜欢的图像。不知道它在 ios 上如何工作,但我认为也有闪屏。
Windows/Linux/Mac/RPi:
这些上不存在这样的东西。也许你可以用 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
设置过渡外观的长度 here,应该可以在过渡中访问,例如FadeTransition(duration=1.5)