# 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]

# Read and write to the clipboard

## Read and write to the clipboard

The following demo shows how to use `ui.clipboard.read()`, `ui.clipboard.write()` and `ui.clipboard.read_image()` to interact with the clipboard.

Note that your browser may ask for permission to access the clipboard or may not support this feature at all.

main.py

[Button]

````python
from nicegui import ui

ui.button('Write Text', on_click=lambda: ui.clipboard.write('Hi!'))

async def read() -> None:
    ui.notify(await ui.clipboard.read())
ui.button('Read Text', on_click=read)

async def read_image() -> None:
    img = await ui.clipboard.read_image()
    if not img:
        ui.notify('You must copy an image to clipboard first.')
    else:
        image.set_source(img)
ui.button('Read Image', on_click=read_image)
image = ui.image().classes('w-72')

ui.run()
````

## Client-side clipboard

In order to avoid the round-trip to the server, you can also use the client-side clipboard API directly.
This might be supported by more browsers because the clipboard access is directly triggered by a user action.

main.py

[Button]

````python
from nicegui import ui

ui.button('Write').on('click', js_handler='''
    () => navigator.clipboard.writeText("Ho!")
''')
ui.button('Read').on('click', js_handler='''
    async () => emitEvent("clipboard", await navigator.clipboard.readText())
''')
ui.on('clipboard', lambda e: ui.notify(e.args))

ui.run()
````

**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)