Drag and drop

Pyzed has a complete drag and drop system: everything that apps such as Trello, Notion, form builders, website builders, Figma or a shader node editor do with the mouse (and the finger). It is inspired by the best web libraries (dnd-kit, SortableJS, react-beautiful-dnd and Pragmatic drag and drop), but runs natively: the preview that follows the pointer, the items that slide aside, the shadow where the item will land and the flight to its new place are drawn frame by frame without calling Python, so it stays smooth with hundreds of items.
Three building blocks
Section titled “Three building blocks”| Block | What it is | Like |
|---|---|---|
pz.draggable |
Something the pointer can pick up: a card, a shape, a tool, a node’s output. | useDraggable in dnd-kit |
pz.droppable |
A place that takes it: a trash can, a canvas, an input port. | useDroppable in dnd-kit |
pz.sortable |
A list, row or grid whose items you reorder, and move between lists. | SortableJS, react-beautiful-dnd |
A fourth one, pz.drag_handle, marks the part of an item that
starts the drag (the dots of a row, the title of a window).
import pyzed as pzfrom pyzed import ui
class Todo(pz.App): def __init__(self): self.tasks = ["Buy milk", "Answer emails", "Book flights"]
def view(self): return pz.sortable( items=self.tasks, item=lambda task: ui.card(ui.label(task)), key=str, on_reorder=lambda event: pz.dnd.move(self.tasks, event), )
pz.run(Todo)That is a list you reorder by dragging: the other rows slide out of the way, a shadow shows
where the row will land, and on release it glides there. Python only hears about the drop
(on_reorder) and pz.dnd.move applies it to
your list.
What you can build
Section titled “What you can build”- Boards and lists (Trello, Jira, Notion): sortable lists
with the same
groupmove cards between columns. Tutorial. - Form and page builders (Typeform, Webflow, Elementor): a palette whose items are
copied (
pull="clone"), nested lists, handles and a trash can. Form builder, page builder. - Design canvases (Figma, Canva): free positions, a grid to snap to and guides that align shapes with each other. Tutorial.
- Node editors (shader graphs, Blender, Unreal Blueprints): wires dragged from an output to a compatible input. Tutorial.
- Grids, tabs and folders: photo grids that wrap, tabs that only slide sideways, files you drop onto a folder to group them (combine).
Everything it does
Section titled “Everything it does”- Animations: the item lifts with a shadow, the others make room smoothly, the dropped item flies to its place, and a cancelled drag (Esc) flies back home. Previews and animations.
- Placeholders: a shadow or a translucent ghost of the item where it will land.
- Rules:
typeandaccepts,can_dropfunctions, lists that only give (put=False), only copy (pull="clone"), don’t reorder (sort=False), are full (max_items) or have pinned items (locked). Conditions. - Limits: drag only by a handle, along one axis, inside a parent, in grid steps, after a long press (touch screens). Handles.
- Canvases: drop coordinates, snapping to a grid and alignment guides. Free canvas.
- Scrolling: lists inside a scrollable scroll by themselves when you drag near an edge.
- Keyboard: sortables can be reordered with Alt+arrows. Keyboard and touch.
Where to start
Section titled “Where to start”All the examples are in examples/dnd/
and in the welcome gallery of Pyzed Design.