在 Kivy 中启动画面超时后启动主应用程序

Launch main App after Splash Screen timedout in Kivy

我想在 python 中制作一个基于 GUI 的应用程序。我正在使用 Kivy 中的 FileBrowser 作为主要应用程序。

我想显示启动画面大约 5 秒,然后我想启动主应用程序,即 FileBrowser

我在下面提供了我正在使用的文件浏览器和启动画面的代码。

# FileBrowser
class TestApp(App):

    def build(self):

        user_path = os.path.join(browser_base.get_home_directory(), 'Documents')
        browser = browser_base.FileBrowser(select_string='Select',
                              favorites=[(user_path, 'Documents')])
        browser.bind(on_success=self._fbrowser_success,
                     on_canceled=self._fbrowser_canceled,
                     on_submit=self._fbrowser_submit)
        return browser

    def _fbrowser_canceled(self, instance):
        print('cancelled, Close self.')
        self.root_window.hide()
        sys.exit(0)


    def _fbrowser_success(self, instance): # select pressed
        global file

        print(instance.selection)

        file = instance.selection[0]



    def _fbrowser_submit(self, instance): # clicked on the file
        global file

        print(instance.selection)

        file = instance.selection[0]

TestApp().run()

# Splash Screen..!!

class timer():
    def work1(self):
        print('Hello')


class arge(App):
    def build(self):
        wing = Image(source='grey.png', pos=(800, 800))
        animation = Animation(x=0, y=0, d=2, t='out_bounce')
        animation.start(wing)

        Clock.schedule_once(timer.work1, 5)
        return wing

arge().run()

我想 运行 这个闪屏应用程序 5 秒钟,然后启动主应用程序,即由 TestApp class 定义的 FileBrowser。

我该怎么做?

您正在为每个屏幕创建单独的应用程序。相反,您只需要 ScreenManager。下面是一个简单的例子,让你看看 ScreenManager 是如何工作的:

class PgBrowser(Screen):
    # Builder.load_file("browser.kv")

    def on_pre_enter(self, *args):
        filechooser = FileChooserIconView(path=os.path.expanduser('~'),
                                          size=(self.width, self.height),
                                          pos_hint={"center_x": .5, "center_y": .5})
        filechooser.bind(on_submit=self.on_selected)
        self.add_widget(filechooser)

    def on_selected(self, widget_name, file_path, mouse_pos):
        print "Selected: %s" % file_path[0]

class PgSplash(Screen):
    # Builder.load_file("splash.kv")

    def skip(self, dt):
        screen.switch_to(pages[1])

    def on_enter(self, *args):
        Clock.schedule_once(self.skip, 2)

        print "Wait..."

pages = [PgSplash(name="PgSplash"),
         PgBrowser(name="PgBrowser")]

screen = ScreenManager()
screen.add_widget(pages[0])

class myApp(App):
    def build(self):
        screen.current = "PgSplash"
        return screen

myApp().run()