# NiceGUI

[Button: icon:menu]

[](/zh)

[安装](/zh#installation)

[特性](/zh#features)

[演示](/zh#demos)

[文档](/zh/documentation)

[示例](/zh/examples)

[为什么？](/zh#why)

[Button]

[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

在浏览器中呈现的 Python UI 框架。

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

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

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

资源

[文档](/zh/documentation)

[示例](/zh/examples)

[LLM 参考](/llms.txt)

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

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

社区

[讨论区](https://github.com/zauberzeug/nicegui/discussions)

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

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

[参与贡献](https://github.com/zauberzeug/nicegui/blob/main/CONTRIBUTING.md)

[赞助者](https://github.com/sponsors/zauberzeug)

法律

[法律声明](/zh/imprint_privacy#imprint)

[隐私](/zh/imprint_privacy#privacy)

由 [Zauberzeug](https://zauberzeug.com) 用 NiceGUI 打造

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