带有渐变效果的Kivy Splash屏幕图像 [英] Kivy Splash Screen image with fade in effect
问题描述
我想知道如何用猕猴桃制作一个初始屏幕,并在淡入淡出的状态下显示图片几秒钟.
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)
这会在屏幕上显示我的徽标,并在3秒钟后消失,但它会等待应用启动,因此在加载应用时只有一个黑色窗口.
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.
推荐答案
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:
在这些东西上不存在这样的东西.在为OS打包时,也许可以使用 PyInstaller 进行设置,否则,您需要自己进行设置.我可以建议您使用 ScreenManager
及其Transitions
与 Clock
甚至示例
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
要设置过渡的长度,请在此处,在转换过程中应该可以访问它,例如FadeTransition(duration=1.5)
To set a length of a transition look here, which should be accessible within transitions e.g. FadeTransition(duration=1.5)
这篇关于带有渐变效果的Kivy Splash屏幕图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!