tkinter.dnd --- 拖放支援¶
備註
這是一個實驗性的功能,並將在被 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 (see繫結與事件). 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).
目標物件的選擇過程如下:
由上而下搜尋滑鼠下方的區域以尋找目標元件(widget)
目標元件應該要有一個可呼叫的dnd_accept 屬性(attribute)
如果dnd_accept 不存在或回傳
None,搜尋會移至父元件如果找不到目標元件,則目標物件為
None
呼叫<old_target>.dnd_leave(source, event)
呼叫<new_target>.dnd_enter(source, event)
呼叫<target>.dnd_commit(source, event) 以通知放下動作
呼叫<source>.dnd_end(target, event) 以表示拖放結束
- classtkinter.dnd.DndHandler(source,event)¶
DndHandler 類別處理拖放事件,它會追蹤事件元件的根上的 Motion 和 ButtonRelease 事件。
- cancel(event=None)¶
取消拖放過程。
- finish(event,commit=0)¶
執行拖放結束函式。
- on_motion(event)¶
在拖動過程中檢查滑鼠下方的區域以尋找目標物件。
- on_release(event)¶
當釋放模式被觸發時,發出拖動結束的訊號。
- tkinter.dnd.dnd_start(source,event)¶
用於拖放過程的工廠函式。
也參考