How to delete the values of flet python text fields after clicking the button?

Question:

I use Flet Python framework
And I want to delete its values after clicking on the button and store them in the data table

def main(page: ft.Page):
    def btn_click(e):
        if not sstid.value:
            sstid.error_text = "err"
            page.update()
        else:
            my_dict["sstid"] = sstid.value
            page.update()


page.add(
        ft.Container(
            height=250,
            # bgcolor="white10",
            bgcolor="white10",
            border=border.all(1,"#ebebeb"),
            border_radius=8,
            padding=15,
            content=Column(
            expand=True,
            controls=[
                        ft.ElevatedButton("add", on_click=btn_click),


],
)
)

Asked By: Navrang

||

Answers:

def main(page: ft.Page):
    my_dict = {}

    def btn_click(e):
        if not sstid.value:
            sstid.error_text = "err"
            page.update()
        else:
            my_dict["sstid"] = sstid.value
            sstid.set_value("")  # clear the value of sstid
            page.update()

    sstid = ft.TextField(label="SSTID", name="sstid")

    page.add(
        ft.Container(
            height=250,
            bgcolor="white10",
            border=border.all(1,"#ebebeb"),
            border_radius=8,
            padding=15,
            content=Column(
                expand=True,
                controls=[
                    sstid,
                    ft.ElevatedButton("Add", on_click=btn_click),
                ],
            ),
        )
    )
Answered By: NoobCoder
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.