[Python] updating current value in flet

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    Good evening, Based on tutorial here : Flet tutorial

    i am following the codes , everything and i would like to ask one question, here is my code :

    import flet as ft
    from flet import *

    def main(page:ft.Page):
    greeting =ft.Ref[ft.Column]()
    def hello_here(e):
    greeting.current.controls.append(ft.Text(f'hello {first_name.current.value} {last_name.current.value}'))
    first_name.current.value =""
    last_name.current.value =""
    first_name.current.focus()
    page.update()

    page.title="My greatings"
    first_name =ft.Ref[ft.TextField]()
    last_name =ft.Ref[ft.TextField]()

    page.add(
    ft.TextField(ref=first_name,label="Enter First Name",autofocus=True),
    ft.TextField(ref=last_name,label="Enter Last Name"),
    ft.Column(ref=greeting),
    ft.ElevatedButton(text='Say Hello',
    on_click=hello_here)

    )


    ft.app(target=main)


    if i run it :flet flet_ref_example.py

    i got this result : [​IMG]

    as you see, every time, we are adding elements, it is printed on page one following to another, is it possible to make a simple correction and old text should be replaced by new one? i think this line should be corrected

    greeting.current.controls.append(ft.Text(f'hello {first_name.current.value} {last_name.current.value}'))


    but how?

    Continue reading...

Compartilhe esta Página