tkinter.dnd
--- 拖放支援¶
備註
This is experimental and due to be deprecated when it is replacedwith the Tk DND.
Thetkinter.dnd
module provides drag-and-drop support for objects withina single application, within the same window or between windows. To enable anobject to be dragged, you must create an event binding for it that starts thedrag-and-drop process. Typically, you bind a ButtonPress event to a callbackfunction that you write (seeBindings and Events). The function shouldcalldnd_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 callablednd_accept attribute
Ifdnd_accept is not present or returns
None
, search moves to parent widgetIf no target widget is found, then the target object is
None
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
- classtkinter.dnd.DndHandler(source,event)¶
TheDndHandler class handles drag-and-drop events tracking Motion andButtonRelease events on the root of the event widget.
- cancel(event=None)¶
Cancel the drag-and-drop process.
- finish(event,commit=0)¶
Execute end of drag-and-drop functions.
- on_motion(event)¶
Inspect area below mouse for target objects while drag is performed.
- on_release(event)¶
Signal end of drag when the release pattern is triggered.
- tkinter.dnd.dnd_start(source,event)¶
Factory function for drag-and-drop process.