# NiceGUI

[Button: icon:menu]

[](/)

[Installation](/#installation)

[Features](/#features)

[Demos](/#demos)

[Documentation](/documentation)

[Examples](/examples)

[Why?](/#why)

[Button]

[Button]

[](https://github.com/zauberzeug/nicegui/)

[Button: icon:more_vert]

# Event

## Event

Events are a powerful tool distribute information between different parts of your code,
especially from long-living objects like data models to the short-living UI.

Handlers can be synchronous or asynchronous.
They can also take arguments if the event contains arguments.

*Added in version 3.0.0*

main.py

[Button]

````python
from nicegui import Event, ui

tweet = Event[str]()

@ui.page('/')
def page():
    with ui.row(align_items='center'):
        message = ui.input('Tweet')
        ui.button(icon='send', on_click=lambda: tweet.emit(message.value)).props('flat')

    tweet.subscribe(lambda m: ui.notify(f'Someone tweeted: "{m}"'))

ui.run()
````

## Emitting vs. calling events

The `emit` method fires the event without waiting for the subscribed callbacks to complete.
If you want to wait for the subscribed callbacks to complete, use the `call` method.

The following demo shows how to use `call` to reset the button state after the event has been called.

Note that in this particular case, `submit` could also call `backup` directly.
But in some situations an event can help to decouple the code.

main.py

[Button]

````python
import asyncio
from nicegui import Event, ui

data_submitted = Event[str]()

@data_submitted.subscribe
async def backup(data: str):
    print(f'Saving "{data}"...')
    await asyncio.sleep(1)  # simulate writing to database

@ui.page('/')
def page():
    async def submit():
        button.disable()
        try:
            await data_submitted.call(data.value)
            data.value = None
        except Exception as e:
            ui.notify(f'Error: {e}', color='negative')
        finally:
            button.enable()

    with ui.row(align_items='center'):
        data = ui.input('Data')
        button = ui.button('Submit', on_click=submit).props('flat')

ui.run()
````

## Reference

## Methods

**`call`**`(*args: P.args, kwargs: P.kwargs) -> None`

Fire the event and wait asynchronously until all subscribed callbacks are completed.

**`emit`**`(*args: P.args, kwargs: P.kwargs) -> None`

Fire the event without waiting for the subscribed callbacks to complete.

**`emitted`**`(timeout: float | None = None) -> Any`

Wait for an event to be fired and return its arguments.

:param timeout: the maximum time to wait for the event to be fired (default: ``None`` meaning no timeout)

**`subscribe`**`(callback: Callable[P, Any] | Callable[[], Any], expect_args: bool | None = None, unsubscribe_on_delete: bool | None = None) -> None`

Subscribe to the event.

The ``unsubscribe_on_delete`` can be used to explicitly define
whether the callback should be automatically unsubscribed when the current client is deleted.
By default, the callback is automatically unsubscribed if subscribed from within a UI context
to prevent memory leaks.

:param callback: the callback which will be called when the event is fired
:param expect_args: whether to forward the event's arguments to the callback
    (default: ``None`` meaning auto-detected from the callback's signature, *added in version 3.13.0*)
:param unsubscribe_on_delete: whether to unsubscribe the callback when the current client is deleted
    (default: ``None`` meaning the callback is automatically unsubscribed if subscribed from within a UI context)

**`unsubscribe`**`(callback: Callable[P, Any] | Callable[[], Any]) -> None`

Unsubscribe a callback from the event.

:param callback: the callback to unsubscribe from the event

**Nice**GUI

The Python UI framework that shows up in your browser.

[](https://github.com/zauberzeug/nicegui/)

[](https://discord.gg/TEpFeAaF4f)

[](https://www.reddit.com/r/nicegui/)

Resources

[Documentation](/documentation)

[Examples](/examples)

[LLM reference](/llms.txt)

[GitHub](https://github.com/zauberzeug/nicegui/)

[PyPI](https://pypi.org/project/nicegui/)

Community

[Discussions](https://github.com/zauberzeug/nicegui/discussions)

[Discord](https://discord.gg/TEpFeAaF4f)

[Reddit](https://www.reddit.com/r/nicegui/)

[Contributing](https://github.com/zauberzeug/nicegui/blob/main/CONTRIBUTING.md)

[Sponsors](https://github.com/sponsors/zauberzeug)

Legal

[Imprint](/imprint_privacy#imprint)

[Privacy](/imprint_privacy#privacy)

Made with NiceGUI by [Zauberzeug](https://zauberzeug.com)

© 2026 [Zauberzeug GmbH](https://zauberzeug.com)