async callback and ui element with Element.on method #280
-
Beta Was this translation helpful? Give feedback.
Answered by
falkoschindler
Jan 23, 2023
Replies: 1 comment 5 replies
-
It looks like there is a limitation in the generic event subscription using import asyncio
from nicegui import ui
async def handle_click():
await asyncio.sleep(0.1)
ui.notify('clicked')
ui.button('Works', on_click=handle_click)
ui.button('Fails').on('click', lambda _: handle_click())
ui.run() The event handler for A workaround for you would be to explicitly set the context in with card:
absolute_app_card(app, x - rec.x, y - rec.y) This way the Let me know if this works. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
SebastienDorgan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like there is a limitation in the generic event subscription using
.on()
. Here is a minimum reproduction:The event handler for
on_click
will automatically keep the current UI context open as long as some async function is awaited..on()
should do that as well. I'll open a new issue.A workaround for you would be to explicitly set the context in
on_drag_end
somehow like this:This way the
ui.card()