1:mod:`tkinter.dnd` --- Drag and drop support 2============================================ 3 4.. module:: tkinter.dnd 5 :platform: Tk 6 :synopsis: Tkinter drag-and-drop interface 7 8**Source code:** :source:`Lib/tkinter/dnd.py` 9 10-------------- 11 12.. note:: This is experimental and due to be deprecated when it is replaced 13 with the Tk DND. 14 15The :mod:`tkinter.dnd` module provides drag-and-drop support for objects within 16a single application, within the same window or between windows. To enable an 17object to be dragged, you must create an event binding for it that starts the 18drag-and-drop process. Typically, you bind a ButtonPress event to a callback 19function that you write (see :ref:`Bindings-and-Events`). The function should 20call :func:`dnd_start`, where 'source' is the object to be dragged, and 'event' 21is the event that invoked the call (the argument to your callback function). 22 23Selection of a target object occurs as follows: 24 25#. Top-down search of area under mouse for target widget 26 27 * Target widget should have a callable *dnd_accept* attribute 28 * If *dnd_accept* is not present or returns None, search moves to parent widget 29 * If no target widget is found, then the target object is None 30 312. Call to *<old_target>.dnd_leave(source, event)* 32#. Call to *<new_target>.dnd_enter(source, event)* 33#. Call to *<target>.dnd_commit(source, event)* to notify of drop 34#. Call to *<source>.dnd_end(target, event)* to signal end of drag-and-drop 35 36 37.. class:: DndHandler(source, event) 38 39 The *DndHandler* class handles drag-and-drop events tracking Motion and 40 ButtonRelease events on the root of the event widget. 41 42 .. method:: cancel(event=None) 43 44 Cancel the drag-and-drop process. 45 46 .. method:: finish(event, commit=0) 47 48 Execute end of drag-and-drop functions. 49 50 .. method:: on_motion(event) 51 52 Inspect area below mouse for target objects while drag is performed. 53 54 .. method:: on_release(event) 55 56 Signal end of drag when the release pattern is triggered. 57 58.. function:: dnd_start(source, event) 59 60 Factory function for drag-and-drop process. 61 62.. seealso:: 63 64 :ref:`Bindings-and-Events`