cpython/Doc/library/tkinter.dnd.rst
Miss Islington (bot) 82b757071e
[3.15] gh-86726: Document the full public API of tkinter (GH-151579) (GH-151649)
Replace the previously sparse reference documentation with full coverage of
the public API of the tkinter package, written from the Tcl/Tk manual pages,
the existing documentation and the module docstrings.

* Doc/library/tkinter.rst gains a "Reference" section documenting every public
  class, method, function and constant of the core module -- the widgets, the
  Misc, Wm, Pack, Place, Grid, XView and YView mix-ins, the Variable and image
  classes, the module-level functions and the symbolic constants.
* Doc/library/tkinter.ttk.rst, dialog.rst, tkinter.font.rst and the other
  module pages document their remaining classes, methods and functions.

The descriptions are Python-oriented (correct return types -- tuples rather
than Tcl lists, booleans, integers, None on cancellation, and so on) and were
checked against the Tcl/Tk 9.1 manual pages and the implementation.

versionadded, versionchanged and deprecated directives are added for the
public API, determined from the git history relative to Python 3.0: the
tkinter.ttk module (3.1); the Text, Wm, Menu and Misc methods exposing Tk 8.5
features (3.3); and the many later additions and behavior changes up to 3.15.
The Tk version required by features added after Tk 8.6 is noted as well.  The
bundled Tcl/Tk version is updated to 9.0 and the manual-page links point at
the tcl9.0 reference.

--------
(cherry picked from commit 8b270b72a2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-06-18 12:47:36 +00:00

66 lines
2.2 KiB
ReStructuredText

:mod:`!tkinter.dnd` --- Drag and drop support
=============================================
.. module:: tkinter.dnd
:synopsis: Tkinter drag-and-drop interface
**Source code:** :source:`Lib/tkinter/dnd.py`
--------------
.. note:: This is experimental and due to be deprecated when it is replaced
with the Tk DND.
The :mod:`!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 :ref:`Bindings-and-Events`). The function should
call :func:`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).
Selection of a target object occurs as follows:
#. Top-down search of area under mouse for target widget
* Target widget should have a callable *dnd_accept* attribute
* 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``
2. Call to *<old_target>.dnd_leave(source, event)*
#. Call to *<new_target>.dnd_enter(source, event)*
#. Call to *<target>.dnd_commit(source, event)* to notify of drop
#. Call to *<source>.dnd_end(target, event)* to signal end of drag-and-drop
.. class:: DndHandler(source, event)
The *DndHandler* class handles drag-and-drop events tracking Motion and
ButtonRelease events on the root of the event widget.
.. method:: cancel(event=None)
Cancel the drag-and-drop process.
.. method:: finish(event, commit=0)
Execute end of drag-and-drop functions.
.. method:: on_motion(event)
Inspect area below mouse for target objects while a drag
is performed.
.. method:: on_release(event)
Signal end of drag when the release pattern is triggered.
.. function:: dnd_start(source, event)
Factory function for the drag-and-drop process.
Return the :class:`DndHandler` instance managing the drag, or ``None`` if a
drag could not be started.
.. seealso::
:ref:`Bindings-and-Events`