Closed muratbedir closed 10 months ago
@muratbedir Sorry, can you, please, reduce this example to the bare minimum? In its current form the app isn't even starting without modification due to missing storage entries, all of which probably isn't needed for reproducing the issue. I guess you only need a single button and a dialog?
Hi Falco, thanks for help, in using below code you can reproduce problem.
Problem is : when pressed "open dialog" its open dialog without any problem via ui.button('open dialog',on_click=lambda: (about())).props('outline round')
code
but when I select about from menu via ui.button('open dialog',on_click=lambda: (about())).props('outline round')
dialog box does not open but strangely I presses hamburger menu icon its openning.
Thanks for help.
from nicegui import app, ui
@ui.page('/')
def main_page() -> None:
menu()
with ui.column().classes('absolute-center items-center') :
ui.label("SMS test uygulaması").classes('text-2xl text-positive')
ui.button('open dialog',on_click=lambda: (about())).props('outline round')
@ui.page('/subpage')
def test_page() -> None:
ui.label('This is a sub page.')
def about():
with ui.dialog() as dialog, ui.card():
ui.label('(c) 2023 A.Ş. ')
ui.button('close', on_click=lambda: ui.open("/"))
return dialog
def menu():
with ui.row().classes('w-full items-center'):
result = ui.label().classes('mr-auto')
with ui.button(icon='menu'):
with ui.menu() as menu:
ui.menu_item('About', on_click=lambda:(about()) )
ui.menu_item('Google 2', lambda: ui.open("https://www.google.com") )
ui.menu_item('Menu item 3', lambda: result.set_text('Selected item 3'))
ui.run(storage_secret='THIS_NEEDS_TO_BE_CHANGED',port=7654)
Thanks! So the problem boils down to this:
def about():
with ui.dialog() as dialog, ui.card():
ui.label('About')
return dialog
ui.button('About', on_click=about) # works
with ui.button('Menu'):
with ui.menu():
ui.menu_item('About', on_click=about) # doesn't work
Very strange... I'll look into it.
Oh, I see. It's because NiceGUI's event handler creates new elements in the same context like the element which causes the event:
I'd recommend creating the dialog once and opening/closing it when needed:
with ui.dialog() as about, ui.card():
ui.label('About')
ui.button('Close', on_click=about.close)
ui.button('About', on_click=about.open)
with ui.button('Menu'):
with ui.menu():
ui.menu_item('About', on_click=about.open)
I understand problem, after your recommended modification, its working well, I share modified code in below for reference.
But in this case, I need to pass about dialogbox's reference to menu() function because its scope different.
from nicegui import app, ui
@ui.page('/')
def main_page() -> None:
with ui.dialog() as about, ui.card():
ui.label('About')
ui.button('Close', on_click=about.close)
menu(about)
with ui.column().classes('absolute-center items-center') :
ui.label("SMS test uygulaması").classes('text-2xl text-positive')
ui.button('open dialog',on_click=about.open).props('outline round')
@ui.page('/subpage')
def test_page() -> None:
ui.label('This is a sub page.')
def menu(about):
with ui.row().classes('w-full items-center'):
result = ui.label().classes('mr-auto')
with ui.button(icon='menu'):
with ui.menu() as menu:
ui.menu_item('About', on_click=about.open )
ui.menu_item('Google 2', lambda: ui.open("https://www.google.com") )
ui.menu_item('Menu item 3', lambda: result.set_text('Selected item 3'))
ui.run(storage_secret='THIS_NEEDS_TO_BE_CHANGED',port=7654)
Description
Hakkında menu item does not open hakkinda() dialogbox , when I try below sequence dialog box opens via menu
When select Hakkında menu item then thats quits then I click sandwich menu icon dialog box opens I thing this is a bug or I am new to nicegui then I am making smoneting wrong.
but
is open dialog box without any problem.
thanks for help.
*I found nicegui after a lot of searches, before nicegui I used to streamlit but streamlit not customisations options like nicegui.