Tell me how to implement Drag and Drop in pygtk, for example, to get the address of the file transferred to the program window. I found different examples, but they were too complex, did not work or did not work like this: Drag & Drop was inside the program, and the file could not be transferred there.

    1 answer 1

    The event of receiving a file and transmitting information about it is on label2. The form code is loaded from the example.glade file.

    Import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gtk, Gdk, GdkPixbuf class Handler: def onDeleteWindow(self, *args): Gtk.main_quit(*args) def onButtonPressed(self, button): print("Hello World!") def on_drag_data_received(widget, drag_context, data, x, y, selection_data, info, time): print(selection_data.get_uris()) # результат - список путей до файлов в виде python list [] builder = Gtk.Builder() builder.add_from_file("example.glade") builder.connect_signals(Handler()) label2 = builder.get_object("label2") # сигнал в файле glade на событие drag_data_received, функция on_drag_data_received label2.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY) # Получатель label2.drag_dest_add_uri_targets() # что передает, без источника работать отказывается window = builder.get_object("window2") window.show_all() Gtk.main() 

    Signal on label2 (tag) - drag_data_received

    The on_drag_data_received function is running.

    Inside it is a selection_data variable that has a get_uris () property