page.views.clear() It actually causes the program to run abnormally #3537
ChinaGodzilla
started this conversation in
Show and tell
Replies: 3 comments
-
import flet as ft
def main(page: ft.Page):
page.scroll = ft.ScrollMode.AUTO
# page.views.clear()
def add_data(e):
page.controls.clear()
for x in range(100):
aaa = ft.Text(str(x))
page.add(aaa)
page.add(
ft.Row(
controls=[
ft.ElevatedButton(
text="CLEAR",
on_click=clear_all_controls
),
ft.ElevatedButton(
text="ADD DATA",
on_click=add_data
)
]
)
)
page.update()
def clear_all_controls(e):
page.controls.clear()
page.add(
ft.Row(
controls=[
ft.ElevatedButton(
text="CLEAR",
on_click=clear_all_controls
),
ft.ElevatedButton(
text="ADD DATA",
on_click=add_data
)
]
)
)
page.update()
page.add(
ft.Row(
controls=[
ft.ElevatedButton(
text="CLEAR",
on_click=clear_all_controls
),
ft.ElevatedButton(
text="ADD DATA",
on_click=add_data
)
]
)
)
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here is the guide on |
Beta Was this translation helpful? Give feedback.
0 replies
-
another example with view: import flet as ft
def main(page: ft.Page):
page.scroll = ft.ScrollMode.AUTO
# page.views.clear()
def add_data(e):
page.views.clear()
page.views.append(ft.View())
for x in range(10):
aaa = ft.Text(str(x))
page.views[0].controls.append(aaa)
page.views[0].controls.append(
ft.Row(
controls=[
ft.ElevatedButton(
text="CLEAR",
on_click=clear_all_controls
),
ft.ElevatedButton(
text="ADD DATA",
on_click=add_data
)
]
)
)
page.update()
def clear_all_controls(e):
page.views.clear()
page.views.append(ft.View(controls=[
ft.Row(
controls=[
ft.ElevatedButton(
text="CLEAR",
on_click=clear_all_controls
),
ft.ElevatedButton(
text="ADD DATA",
on_click=add_data
)
]
)
]))
page.update()
page.add(
ft.Row(
controls=[
ft.ElevatedButton(
text="CLEAR",
on_click=clear_all_controls
),
ft.ElevatedButton(
text="ADD DATA",
on_click=add_data
)
]
)
)
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
page.views.clear()
Disabling it will work fine, but activating it will cause the program to not run properly.
Beta Was this translation helpful? Give feedback.
All reactions