启动Timekivy主屏幕后启动Splash

2024-05-13 04:14:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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()

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

我怎么能做到呢。?在


Tags: pathinstanceselfbrowser应用程序屏幕ondef
1条回答
网友
1楼 · 发布于 2024-05-13 04:14:43

您正在为每个屏幕创建单独的应用程序。相反,你只需要屏幕管理器。下面是一个简单的示例,让您了解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()

相关问题 更多 >