上一话题

tkinter.scrolledtext — 卷动文本 Widget

下一话题
就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 采用 Tk 的图形用户界面
  9. tkinter.dnd — 拖放支持

tkinter.dnd — 拖放支持 ¶

源代码: Lib/tkinter/dnd.py


注意

This is experimental and due to be deprecated when it is replaced with the 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).

Selection of a target object occurs as follows:

  1. Top-down search of area under mouse for target widget

  • Target widget should have a callable dnd_accept 属性

  • 若 dnd_accept is not present or returns None , search moves to parent widget

  • If no target widget is found, then the target object is None

  1. Call to <old_target>.dnd_leave(source, event)

  2. Call to <new_target>.dnd_enter(source, event)

  3. Call to <target>.dnd_commit(source, event) to notify of drop

  4. 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.

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.

另请参阅

Bindings and Events

上一话题

tkinter.scrolledtext — 卷动文本 Widget

下一话题

tkinter.ttk — Tk 主题 Widget

本页

  • 报告 Bug
  • 展示源

快速搜索

键入搜索术语或模块、类、函数名称。

  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 采用 Tk 的图形用户界面
  9. tkinter.dnd — 拖放支持

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1