代码之家  ›  专栏  ›  技术社区  ›  Eldelshell

区分GTK条目图标

  •  4
  • Eldelshell  · 技术社区  · 15 年前

    我在一个GTK中添加两个图标。PyGTK中的条目。图标信号通过以下方法处理

    def entry_icon_event(self, widget, position, event)
    

    我试图区分这两种情况:

    <enum GTK_ENTRY_ICON_PRIMARY of type GtkEntryIconPosition>
    <enum GTK_ENTRY_ICON_SECONDARY of type GtkEntryIconPosition>
    

    我该怎么做?我一直在挖掘Pygtk的文档,但是没有对象gtKentryIconposition,也没有这个枚举的任何定义。

    谢谢

    2 回复  |  直到 7 年前
        1
  •  1
  •   user285176    15 年前

    有更好的方法:

    def entry_icon_event(self, widget, icon, event):
        if icon == gtk.ENTRY_ICON_PRIMARY:
            ...
        elif icon == gtk.ENTRY_ICON_SECONDARY:
            ...
    
        2
  •  1
  •   Eldelshell    15 年前

    好吧,既然没人回答,那我就照我实际发现的做。使用此图标的方法如下:

    def entry_icon_event(self, widget, icon, event):
        if icon.value_name == "GTK_ENTRY_ICON_PRIMARY":
            print "First Button"
            if event.button == 0:
                print "Left Click":
            else:
                print "Right Click"
        elif icon.value_name == "GTK_ENTRY_ICON_SECONDARY":
            print "Second Button"
            if event.button == 0:
                print "Left Click":
            else:
                print "Right Click"