[Question] Control Refs AttributeError for Row and Column if ".current.controls." is not in a "def XXX(e)" #1519
-
QuestionHi I am new using flet (from tkinter). I realize, when using Control Refs, "ft.Row" and "ft.Column" cannot use ".current.controls." like other controls like TextField if I use it in main (not in another function). in the official Introduction (https://flet.dev/docs/guides/python/getting-started), the sample code is:
The "greetings" are modified in "btn_click(e)". Code sampleimport flet as ft
def main(page):
first_name = ft.Ref[ft.TextField]()
last_name = ft.Ref[ft.TextField]()
greetings = ft.Ref[ft.Column]()
greetings.current.controls.append(
ft.Text(f"whatever text here 111"),
ft.Text(f"whatever text here 222"),
ft.Text(f"whatever text here 333"),
)
page.add(
ft.TextField(ref=first_name, label="First name", autofocus=True),
ft.TextField(ref=last_name, label="Last name"),
ft.Column(ref=greetings),
)
ft.app(target=main) Error messageAttributeError: 'NoneType' object has no attribute 'controls' ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to place |
Beta Was this translation helpful? Give feedback.
You need to place
greetings.control....
after thepage.add(...)
for it to work.The refs first need to be registered (as in your
ref=greetings
) before used. Before this 'binding' theref.current
isNone
since it is not connected to a control.