我想在python中创建一个基于GUI的应用程序。我使用FileBrowser
中的Kivy
作为主要应用程序。
我想在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。
我该怎么做??
答案 0 :(得分:2)
您正在为每个屏幕创建单独的应用程序。相反,您只需要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()