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

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

  1. 대상 위젯에 대한 마우스 아래 영역의 하향식 검색

  • 대상 위젯에는 콜러블 dnd_accept 어트리뷰트가 있어야 합니다

  • dnd_accept가 없거나 None을 반환하면, 검색은 부모 위젯으로 이동합니다

  • 대상 위젯이 발견되지 않으면, 대상 객체는 None입니다.

  1. <old_target>.dnd_leave(source, event)를 호출합니다

  2. <new_target>.dnd_enter(source, event)를 호출합니다

  3. 드롭을 알리기 위해 <target>.dnd_commit(source, event)를 호출합니다

  4. 드래그 앤드 드롭의 끝을 알리기 위해 <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)

드래그 앤드 드롭 프로세스를 위한 팩토리 함수.