flet
flet copied to clipboard
`Control.parent` property
Closes #952
- Issue TBF: The tiles created on_click of the first tile have no parent (
None
) although they all live in thesameColumn
.
Test Code:
import flet as ft
def main(page: ft.Page):
def handle_add_to_parent(e: ft.ControlEvent):
c: ft.Control = e.control
print(f"The clicked {c.__class__.__name__} has parent {c.parent.__class__.__name__}")
if isinstance(c.parent, ft.Column):
c.parent.controls.append(
ft.ListTile(
leading=ft.Icon(ft.icons.ALBUM),
trailing=ft.IconButton(ft.icons.DELETE, on_click=handle_add_to_parent),
title=ft.Text("The Enchanted Nightingale"),
subtitle=ft.Text(
"Music by Julie Gable. Lyrics by Sidney Stein."
),
on_click=handle_add_to_parent
)
)
page.update()
page.add(
ft.Column(
[
ft.ListTile(
leading=ft.Icon(ft.icons.ALBUM),
trailing=ft.IconButton(ft.icons.DELETE, on_click=handle_add_to_parent),
title=ft.Text("The Enchanted Nightingale"),
subtitle=ft.Text(
"Music by Julie Gable. Lyrics by Sidney Stein."
),
on_click=handle_add_to_parent
),
]
)
)
ft.app(target=main)