until now, flet does not support multi pages.
With this tool, you can start new pages on the same script without the need of creating new app
class or new cmd process etc...
pip install flet-multi-page --upgrade
Its very simple, you just need to import the package and import the class subPage
.
This is an example code:
from flet_multi_page import subPage
import flet
def main (page:flet.Page):
def start_new_page (e):
p = subPage(controls=[flet.Text("Hello from the new page!!")], page_props={"bgcolor":"blue"})
p.start()
page.add(flet.ElevatedButton("start new page", on_click=start_new_page))
page.update()
if __name__ == "__main__": #? This is so important, there will be errors without it.
flet.app(target=main)
Or if you want a second target
function for the page you can just add target
argument like this:
from flet_multi_page import subPage
import flet
import random
def second_target (page:flet.Page): #? This is the target function of the second page.
colors = ["blue", "pink", "black", "red", "green"]
page.bgcolor = random.choice(colors)
page.add(flet.Text("Hello new page!", color="white"))
page.update()
def main (page:flet.Page):
def start_new_page (e):
p = subPage(target=second_target) #! This is the "subPage" class.
p.start() #! This will run and start the second page.
page.add(flet.ElevatedButton("start new page", on_click=start_new_page))
page.update()
if __name__ == "__main__": #? This is so important, there will be errors without it.
flet.app(target=main)
controls
argument (optional): You can add the controls you need directly to the new page.page_props
argument (optional): You can add the page properties you want as dict.target
argument (optional): You can set a target function to call for the new page, and getpage
class as an argument.view
argument (optional): The default isFLET_APP
which is a desktop app view, you can change it toflet.WEB_BROWSER
orweb_browser
to make the page open in a web_browser.