Skip to content

until now, flet does not support multi pages. With this you can start new pages on the same script.

License

Notifications You must be signed in to change notification settings

SKbarbon/flet_multi_page

Repository files navigation

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

  • 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 get page class as an argument.
  • view argument (optional): The default is FLET_APP which is a desktop app view, you can change it to flet.WEB_BROWSER or web_browser to make the page open in a web_browser.

About

until now, flet does not support multi pages. With this you can start new pages on the same script.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages