代码之家  ›  专栏  ›  技术社区  ›  Jean-Paul Calderone

以编程方式聚焦hippo.CanvasEntry?

  •  2
  • Jean-Paul Calderone  · 技术社区  · 16 年前

    import pygtk
    pygtk.require('2.0')
    import gtk, hippo
    
    def textClicked(text, event, row):
        input = hippo.CanvasEntry()
        input.set_property('text', text.get_property('text'))
        parent = text.get_parent()
        parent.insert_after(input, text)
        parent.remove(text)
    
    def main():
        canvas = hippo.Canvas()
        root = hippo.CanvasBox()
        canvas.set_root(root)
    
        text = hippo.CanvasText(text=u'Some text')
        text.connect('button-press-event', textClicked, text)
        root.append(text)
    
        window = gtk.Window()
        window.connect('destroy', lambda ignored: gtk.main_quit())
        window.add(canvas)
    
        canvas.show()
        window.show()
    
        gtk.main()
    
    if __name__ == '__main__':
        main()
    

    单击文本标签时创建的画布条目如何在创建时自动聚焦?

    1 回复  |  直到 16 年前
        1
  •  2
  •   Glyph    16 年前

    在下面 CanvasEntry ,这里有一个普通的 gtk.Entry 一旦焦点被显示,你就需要请求焦点。这是您的 textClicked

    def textClicked(text, event, row):
        input = hippo.CanvasEntry()
        input.set_property('text', text.get_property('text'))
        entry = input.get_property("widget")
        def grabit(widget):
            entry.grab_focus()
        entry.connect("realize", grabit)
        parent = text.get_parent()
        parent.insert_after(input, text)
        parent.remove(text)