I'm trying to make some order in a script that uses nicegui. I'm using a dictionary to store all button labels and the pages they will redirect to.
I'm iterating over all keys in pages dictionary and calling ui.button for each of them.
from nicegui import ui
pages = {'page_one':'Page','page_two':'Page 2','page_three':'Page 3'}
for page in pages:
ui.button(pages[page], on_click=lambda page: ui.open(page))
when binding page it becomes a completely different type nicegui.events.ClickEventArguments instead of a normal string
not binding page causes all buttons to redirect to page_three
ui.button(pages[page], on_click=lambda: ui.open(page))
I feel like I completely misunderstand what actually binding is and how lambdas operate.
Why is the page variable changing type when bound to function in this context?
source https://stackoverflow.com/questions/76348605/binding-variable-in-loop-changes-its-type
Comments
Post a Comment