【问题标题】:Launch main App after Splash Screen timedout in Kivy在 Kivy 启动画面超时后启动主应用程序
【发布时间】:2018-03-23 15:36:42
【问题描述】:

我想在 python 中制作一个基于 GUI 的应用程序。我正在使用来自KivyFileBrowser 作为主应用程序。

我想显示一个启动画面 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()

我想运行这个 Splash Screen 应用程序 5 秒钟,然后启动主应用程序,即 TestApp 类定义的 FileBrowser。

我该怎么做?

【问题讨论】:

    标签: python python-3.x user-interface kivy splash-screen


    【解决方案1】:

    您正在为每个屏幕创建单独的应用程序。相反,您只需要 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()
    

    【讨论】:

    • 在运行如您所展示的代码时,在启动屏幕之后浏览器永远不会出现..!!
    • @SreeramTP 不,确实如此。你可能犯了一个错误。
    • 我现在把代码分享给你,让你看看..!
    • 我想加载TestApp类定义的那个浏览器,你能告诉我如何正确完成吗?
    • @SreeramTP 我已经编辑了代码。我在浏览器屏幕上添加了 FileChooserIconView 而不是 FileBrowser,因为我没有下载该花园类。但是,无论如何,您应该实现的方式是相同的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2012-09-11
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多