pygobject creating a drag and drop source

非 Y 不嫁゛ 提交于 2020-02-05 07:20:22

问题


from gi.repository import Gtk, Gdk

def drag_data_get_cb(widget, drag_context, selection_data, info, time):
    print selection_data.get_data_type()
    print widget.get_text()
    return widget.get_text()

def drag_begin_cb(widget, dragcontext):
    print dragcontext, widget
    return dragcontext

label = Gtk.Label()
label.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.COPY)
label.set_text("Drag Me!")
label.connect("drag_data_get", drag_data_get_cb)
label.connect("drag_begin", drag_begin_cb)

window = Gtk.Window()
window.add(label)
window.connect("delete_event", Gtk.main_quit)
window.set_default_size(300, 250)
window.show_all()

Gtk.main()

ive been hitting my head against a wall over this for a few days now, can anyone tell me why this doesnt allow me to drag text into other widgets? neither of the drag events fire at all


回答1:


It says in this tutorial that you cannot use widgets without windows, such as Gtk.Label as drag and drop sources. You can replace the label with a button for instance:

label = Gtk.Button.new_with_label("Drag Me!")

in order for this example to work.



来源:https://stackoverflow.com/questions/7704017/pygobject-creating-a-drag-and-drop-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!