tkinter.dnd --- 拖放操作支持¶
源代码: Lib/tkinter/dnd.py
备注
此模块是实验性的且在为 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 绑定和事件). 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).
目标对象的选择方式如下:
从顶至底地在鼠标之下的区域中搜索目标控件
目标控件应当具有一个指向可调用对象的 dnd_accept 属性
如果 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) 来表明拖放的结束
- class tkinter.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)¶
用于拖放进程的工厂函数。
参见