[pygtk] grab_focus

Alessandro Dentella sandro at e-den.it
Fri May 16 16:54:58 WST 2008


Sorry for the noise. But I added one more false info...



It turns out grab_focus works as expected when I first create the window and
entry. Any successive entry, added to this window will not get the focus.

Following code doesn't ever get the focus to the entry... why?

import gtk

class Layout(object):
    def __init__(self):
        self.w = gtk.Window()
        self.b = gtk.HBox()
        self.w.add(self.b)
        self.butt = gtk.Button(label="add entry")
        self.butt.connect('clicked', self.butt_cb)
        self.b.add(self.butt)
        self.w.show_all()

        self.w2 = gtk.Window()
        self.w2.set_default_size(200, 100)
        self.b2 = gtk.VBox()
        self.w2.add(self.b2)
        
        label = gtk.Label('Entries')
        self.b2.add(label)
        self.w2.show_all()
        
    def butt_cb(self, wdg):
        e = gtk.Entry()
        self.b2.add(e) 
        e.show()
        e.grab_focus()
        self.w2.show_all()

l = Layout()
gtk.main()



More information about the pygtk mailing list