2

我尝试创建一个Gtk.Image处理“单击”信号的自定义,但是当我尝试从自定义发出信号时Gtk.Image,但无法弄清楚为什么当有按钮按下事件时信号不发出。

类 WindowButton(Gtk.Image): gtype_name = "WindowButton"

__gsignals__ = {
    "clicked" : (GObject.SIGNAL_ACTION,None,(Gdk.Event,))
}

def __init__(self,*args,**kwargs):
    Gtk.Image.__init__(self,*args,**kwargs)

    self.set_from_stock(Gtk.STOCK_OK,Gtk.IconSize.SMALL_TOOLBAR)

    self.event = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)

    self.emit("button-press-event",self.event)

    self.connect("button-press-event",self.on_button_press_event)
    self.connect("clicked",self.do_clicked)

def on_button_press_event(self,event):
    print(ButtonPressEvent)
    print(event)

    self.emit("clicked",self.event)

def do_clicked(self,event):
    print('clicked')
    print(event)
4

1 回答 1

1

GtkImage 没有像“点击”这样的信号。将您的 GtkImage 放在 EventBox 中,并将您的信号连接到EventBox

于 2017-04-19T21:24:39.563 回答