how to add widgets on events #729
-
Questionhello, coming from wxpython, it's not clear to me how to add child widgets/controls to a parent widget in nicegui on events. Trying to be more clear, I've modified the splitter example: I would like to create a button on the right when I click on the button on the left. How should the code be changed? In the end my purpose is to create a database browser: when user click on the name of a table in a table list, a qtable appears with records thanks in advance, Marco from nicegui import ui
def add_widget():
splitter.after.button('Here it is')
with ui.splitter() as splitter:
with splitter.before:
ui.label('This is some content on the left hand side.').classes('mr-2')
ui.button('Add widget on right', on_click=add_widget)
with splitter.after:
ui.label('This is some content on the right hand side.').classes('ml-2')
ui.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @mprosperi! def add_widget():
with splitter.after:
ui.button('Here it is') |
Beta Was this translation helpful? Give feedback.
Hi @mprosperi!
With NiceGUI you usually set the context for new elements using
with
expressions. This can be used directly when creating the containers (e.g.with ui.splitter() as splitter:
), but also later to add elements to existing containers: