tkinter.dnd
— Drag and drop support拖放支持¶
Source code: Lib/tkinter/dnd.py
Note
This is experimental and due to be deprecated when it is replaced with the Tk 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. tkinter.dnd
模块为单个应用程序内、同一窗口内或窗口之间的对象提供拖放支持。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). 通常,将ButtonPress事件绑定到编写的回调函数(请参见绑定和事件)。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_start()
,其中“source”是要拖动的对象,“event”是调用该调用的事件(回调函数的参数)。
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目标小部件应具有可调用的dnd_accept属性
If dnd_accept is not present or returns None, search moves to parent widget如果dnd_accept不存在或返回None,搜索将移动到父窗口小部件
If no target widget is found, then the target object is None如果未找到目标小部件,则目标对象为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以明示拖放的结束
-
class
tkinter.dnd.
DndHandler
(source, event)¶ The DndHandler class handles drag-and-drop events tracking Motion and ButtonRelease events on the root of the event widget.DndHandler类处理跟踪事件小部件根上的运动和按钮释放事件的拖放事件。-
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.拖放过程的工厂功能。
See also