tkinter.dnd — Drag and drop support

Código fuente: Lib/tkinter/dnd.py


Nota

Esto es experimental y quedará obsoleto cuando se sustituya por el Tk DND.

The tkinter.dnd module provides drag-and-drop support for objects within a single application, within the same window or between windows. To enable an object to be dragged, you must create an event binding for it that starts the drag-and-drop process. Typically, you bind a ButtonPress event to a callback function that you write (see Enlaces y eventos). The function should call dnd_start(), where “source” is the object to be dragged, and “event” is the event that invoked the call (the argument to your callback function).

La selección de un objeto de destino ocurre de la siguiente manera:

  1. Búsqueda de arriba hacia abajo del área debajo del mouse para el widget de destino

  • El widget de destino debe tener un atributo dnd_accept invocable

  • If dnd_accept is not present or returns None, search moves to parent widget

  • If no target widget is found, then the target object is None

  1. Llama a <old_target>.dnd_leave(source, event)

  2. Llama a <new_target>.dnd_enter(source, event)

  3. Llama a <target>.dnd_commit(source, event) para notificar la caída

  4. Llama a <source>.dnd_end(target, event) para señalar el final de arrastrar y soltar

class tkinter.dnd.DndHandler(source, event)

La clase DndHandler maneja los eventos de arrastrar y soltar que rastrean los eventos Motion y ButtonRelease en la raíz del widget de eventos.

cancel(event=None)

Cancela el proceso de arrastrar y soltar.

finish(event, commit=0)

Ejecuta el fin de las funciones de arrastrar y soltar.

on_motion(event)

Inspecciona el área debajo del mouse en busca de objetos de destino mientras se realiza el arrastre.

on_release(event)

Señal de fin de arrastre cuando se activa el patrón de liberación.

tkinter.dnd.dnd_start(source, event)

Función de fábrica para el proceso de arrastrar y soltar.

Ver también

Enlaces y eventos