tkinter.dnd --- 拖放支援¶
備註
這是一個實驗性的功能,並將在被 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 Bindings and events). 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).
目標物件的選擇過程如下:
Top-down search of the area under the mouse for a target widget:
the target widget should have a callable dnd_accept attribute;
if dnd_accept is not present or returns
None, the search moves to the parent widget;if no target widget is found, 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 the drop.Call to
<source>.dnd_end(target, event)to signal the end of drag-and-drop.
- class tkinter.dnd.DndHandler(source, event)¶
DndHandler 類別處理拖放事件,它會追蹤事件元件的根上的 Motion 和 ButtonRelease 事件。
- cancel(event=None)¶
取消拖放過程。
- finish(event, commit=0)¶
執行拖放結束函式。
- on_motion(event)¶
Inspect area below mouse for target objects while a drag is performed.
- on_release(event)¶
當釋放模式被觸發時,發出拖動結束的訊號。
- tkinter.dnd.dnd_start(source, event)¶
Factory function for the drag-and-drop process. Return the
DndHandlerinstance managing the drag, orNoneif a drag could not be started.