Skip to content
Feeding a clanker? Grab this page as raw .md

CopyToClipboard API#

CopyToClipboard is a single button that writes text_to_copy to the OS clipboard when clicked. Because text_to_copy is a synced traitlet, you can keep setting it from Python and the button always carries the current value — useful for a generated prompt, a connection string, or a block of SQL that the reader needs to paste somewhere else.

See also: ColorPicker for producing a hex string worth copying, AnnotationWidget for capturing text the other direction, and HTMLRefreshWidget for showing that text in the cell instead.

Bases: AnyWidget

Button widget that copies the provided text_to_copy payload.

Examples:

import marimo as mo
from wigglystuff import CopyToClipboard

button = mo.ui.anywidget(CopyToClipboard(text_to_copy="Hello, world!"))
button

Create a CopyToClipboard button.

Parameters:

Name Type Description Default
text_to_copy str

Initial string placed on the clipboard when clicked.

''
**kwargs Any

Forwarded to anywidget.AnyWidget.

{}
Source code in wigglystuff/copy_to_clipboard.py
def __init__(self, text_to_copy: str = "", **kwargs: Any):
    """Create a CopyToClipboard button.

    Args:
        text_to_copy: Initial string placed on the clipboard when clicked.
        **kwargs: Forwarded to ``anywidget.AnyWidget``.
    """
    super().__init__(**kwargs)
    self.text_to_copy = text_to_copy

Synced traitlets#

Traitlet Type Notes
text_to_copy str Payload copied when the button is pressed.