Drag and Drop Python Code Example#

This example demonstrates how to execute a python script by drag’n’drop

To use this example, open napari and drag this file into the viewer.

Tags: interactivity

drag and drop python code
/home/runner/work/docs/docs/.venv/lib/python3.12/site-packages/napari/_qt/qt_event_loop.py:50: UserWarning: System theme detection requires a Qt6 backend. Please switch to PyQt6 or PySide6 to use it.
  theme_type=get_system_theme(),
/home/runner/work/docs/docs/.venv/lib/python3.12/site-packages/napari/_qt/qt_event_loop.py:50: UserWarning: System theme detection requires a Qt6 backend. Please switch to PyQt6 or PySide6 to use it.
  theme_type=get_system_theme(),

<napari._qt.widgets.qt_viewer_dock_widget.QtViewerDockWidget object at 0x7fb430658830>

from napari import Viewer
from napari.types import ImageData


def add_layers(img1: ImageData, img2: ImageData) -> ImageData:
    return img1 + img2

viewer = Viewer()

viewer.open_sample('napari', 'cells3d')
viewer.window.add_function_widget(add_layers)

Gallery generated by Sphinx-Gallery