pygobject创建拖放源 [英] pygobject creating a drag and drop source

查看:63
本文介绍了pygobject创建拖放源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

它在此教程,则不能将没有窗口的窗口小部件(例如Gtk.Label)用作拖放源.您可以将标签替换为按钮,例如:

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.

这篇关于pygobject创建拖放源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆