The following code is ported from an example of the (old) PyGTK manual , which, it seems to me, inspired the accepted answer , but with pygi:
#!/usr/local/env python import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk, Gdk def motion_cb(wid, context, x, y, time): Gdk.drag_status(context, Gdk.DragAction.COPY, time) return True def drop_cb(wid, context, x, y, time): l.set_text('\n'.join([str(t) for t in context.list_targets()])) context.finish(True, False, time) return True w = Gtk.Window() w.set_size_request(200, 150) w.drag_dest_set(0, [], 0) w.connect('drag-motion', motion_cb) w.connect('drag-drop', drop_cb) w.connect('destroy', lambda w: Gtk.main_quit()) l = Gtk.Label() w.add(l) w.show_all() Gtk.main()
source share