Scroll with Arrow key or Page Down/Up #3384
Unanswered
mhshamgholi
asked this question in
Q&A
Replies: 2 comments
-
i found a solution. here is the code. but i don't know whether this is the best practice or not. def main(page: ft.Page):
def on_keyboard(e: ft.KeyboardEvent):
if e.key == "Arrow Up":
r.scroll_to(delta=-40, duration=200)
elif e.key == "Arrow Down":
r.scroll_to(delta=40, duration=200)
else:
pass
# gv = ft.GridView(expand=True, max_extent=150, child_aspect_ratio=1)
r = ft.Row(wrap=True, scroll="always", expand=True)
page.on_keyboard_event = on_keyboard
page.add(r)
for i in range(500):
r.controls.append(
ft.Container(
ft.Text(f"Item {i}"),
width=150,
height=150,
alignment=ft.alignment.center,
bgcolor=ft.colors.AMBER_100,
border=ft.border.all(1, ft.colors.AMBER_400),
border_radius=ft.border_radius.all(5),
)
)
page.update()
ft.app(target=main) we must add more lines for Page Up/Down keys. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Nice solution! |
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
Uh oh!
There was an error while loading. Please reload this page.
-
thank you with your great work.
there is an example in flet doc https://flet.dev/docs/guides/python/large-lists/#gridview
i ran this example and i can scroll with mouse but not with arrow keys (up/down) or page up/down.
how can i scroll with them ?
Beta Was this translation helpful? Give feedback.
All reactions