Search code examples
progress-barflet

ProgressBar flet


Someone knows how to disable the progressBar on Flet?

    pb = ft.ProgressBar(width=700, color="red", bgcolor="#eeeeee")

I already read https://flet.dev/docs/controls/progressbar/ but I don't find a propety that could work to deactivate and activate it

To deactivate the progressBar and activate when I want to?


Solution

  • All flet controls have a show/hide attribute. See here for more information. flet samples can be modified so that the progress bar is hidden when the screen is activated, but can be displayed by clicking a button.

    from time import sleep
    
    import flet as ft
    
    def main(page: ft.Page):
        pb = ft.ProgressBar(width=400, visible=False)
    
        def start(e):
            pb.visible=True
            for i in range(0, 101):
                pb.value = i * 0.01
                sleep(0.1)
                page.update()
                
        page.add(
            ft.Text("Linear progress indicator", style="headlineSmall"),
            ft.ElevatedButton("Indicator start", on_click=start),
            ft.Column([ ft.Text("Doing something..."), pb]),
        )
    
    ft.app(target=main)