将 button_press_event 添加到 Gtk.Image?
Adding button_press_event to Gtk.Image?
我尝试创建一个自定义 Gtk.Image
来处理 "clicked" 信号,但是当我尝试从自定义 Gtk.Image
发出信号时,却无法弄清楚为什么不'当有按钮按下事件时发出信号。
class 窗口按钮(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)
GtkImage 没有像 'clicked' 这样的信号。将您的 GtkImage 放在 EventBox 中并将您的信号挂接到 EventBox.
我尝试创建一个自定义 Gtk.Image
来处理 "clicked" 信号,但是当我尝试从自定义 Gtk.Image
发出信号时,却无法弄清楚为什么不'当有按钮按下事件时发出信号。
class 窗口按钮(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)
GtkImage 没有像 'clicked' 这样的信号。将您的 GtkImage 放在 EventBox 中并将您的信号挂接到 EventBox.