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

대상 객체는 다음과 같이 선택됩니다:

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

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

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

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

  5. 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 DndHandler instance managing the drag, or None if a drag could not be started.

더 보기

Bindings and events