SKbarbon / flet_multi_page

until now, flet does not support multi pages. With this you can start new pages on the same script.
MIT License
52 stars 1 forks source link

flet_multi_page

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...

install

pip install flet-multi-page --upgrade

little peek

Screen Recording 2023-04-27 at 3 22 44 PM

usage

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)

subPage properties