简体   繁体   English

奇异果载入画面

[英]Kivy loading screen

I am currently trying to make a loading screen for Kivy application by switching screens. 我目前正在尝试通过切换屏幕来制作Kivy应用程序的加载屏幕。

#: import FadeTransition kivy.uix.screenmanager.FadeTransition


MyScreenManager:
    id: myscreenmanager
    transition: FadeTransition()
    PreLoadScreen:
    LoadingScreen:
    LoginScreen:

<PreLoadScreen>: 
    ...
<LoadingScreen>: 
    ...
<LoginScreen>: 
    ...

I am aware of how to change the screen by pushing a button like this. 我知道如何通过按这样的按钮来更改屏幕。

    Button:
        text: 'Log In'
        on_release: 
        app.root.current = 'somescreen'

But I could not figure out how to automatically change the screen like, 但我不知道如何自动更改屏幕,

(blank screen) (黑屏)

~automatically fades to 〜自动淡入

-> (screen with loading animation or image) ->(带有加载动画或图像的屏幕)

~when some loadings are done, fades to 〜当完成一些加载后,淡入

-> (login screen) ->(登录屏幕)

Is there a good way I can do this without making any action such as on_release or on_touch_down? 我有什么好方法可以执行此操作而无需执行任何操作,例如on_release或on_touch_down?

Create the following python classes for each Kivy screen: 为每个Kivy屏幕创建以下python类:

class PreLoadScreen(Screen):
   def switchToNextScreen(self) 
      self.parent.current = 'LoadingScreen'

class LoadingScreen(Screen):
    def switchToNextScreen(self):
        self.parent.current = 'PreLoadScreen'

class PreLoadScreen(Screen):
    def switchToNextScreen(self):
        self.parent.current = 'PreLoadScreen'

And then depending on your screen switch conditions, call switchToNextScreen, when you want to switch the current screen being displayed. 然后,根据您的屏幕切换条件,当您想要切换当前显示的屏幕时,调用switchToNextScreen。

self.parent is the equivalent to app.root in your case. self.parent在您的情况下等同于app.root。 As you nest further into a class you will have to call parent repeatedly (self.parent.parent) 当您进一步嵌套到一个类中时,您将不得不反复调用parent(self.parent.parent)

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM