I'm working on a Python Flet project and I'm looking for resources on developing a splash screen for my desktop application. I found some resources in the Flet documentation regarding page.splash, but my requirements are different. I was able to successfully implement the splash screen part using button clicks and routing, but I don't want my users to have to click on start. I want them to navigate directly to the home screen after a certain amount of time.
I tried to call a function inside one of the pages which acts as a view, but it doesn't have the ft.Page parameter, so I'm not able to use that feature. I also tried to create the splash screen by using the sleep() function and calling a function with the event, but that didn't work either. Is there any way I can achieve this, or how can I find out which view is currently at the top?
Main Page
import flet as ft
from flet import *
import time
from pages.index import _view_ as v1
from pages.home import _view_ as v2
from pages.contact import _view_ as v3
from pages.index import page_nav
def master(page=ft.Page):
page.title="Routing"
page.window_height=250
page.window_width=250
page.window_center()
index=v1()
home=v2()
contact=v3()
def route_change(route):
page.views.clear()
if page.route == "/home":
page.window_visible=True
page.update()
page.window_maximized=True
page.views.append(home)
if page.route == "/contact":
page.views.append(contact)
if page.route == "/index":
page.views.append(index)
page.update()
def view_pop(view):
page.views.pop()
top_view=page.views[-1]
page.go(top_view.route)
page.on_route_change=route_change
page.on_view_pop=view_pop
page.go(page.route)
page.views.append(contact)
page.views.append(home)
page.views.append(index)
page.update()
ft.app(target=master)
My splash Page
from flet import View
import flet as ft
from flet import *
import random
import time
rand_clr=random.randint(000000,999999)
time.sleep(3)
page_nav(e)
def page_nav(e):
e.page.window_visible=False
e.page.update()
e.page.go("/home")
btn= ft.FilledButton(
text="Go to home",
width=120,
height=40,
on_click=lambda e: page_nav(e) )
def _view_():
return ft.View(
"/index",
controls=[
ft.Column(
controls=[
ft.Container(
width=120,
height=120,
bgcolor=f'#{rand_clr}',
content=Text("Index Page")),
]
)])