wxPython: Default Frame button?

Cliff Wells clifford.wells at comcast.net
Mon Aug 4 02:24:58 EDT 2003


On Sun, 2003-08-03 at 03:11, Miki Tebeka wrote:
> Hello All,
> 
> I have a frame that contains a panel and several buttons.
> I'd like to make one of the button the default button but 
> self.SetDefaultItem(btn) or btn.SetFocus() don't work. The item in
> focus is a text control inside the panel.
> 
> Any Ideas? (see short example below)

In general, the only child of a frame should be a panel or some other
container (like a splitter).  Frames should generally only have one
child.  Make the button a child of the panel rather than a sibling.

Here's your code, hacked up a bit:


import wx

class P(wx.Panel):
    def __init__(self, parent, id = -1):
        wx.Panel.__init__(self, parent, id)
        sizer = wx.BoxSizer(wx.VERTICAL)

        b = wx.Button(self, -1, "Quit")
        wx.EVT_BUTTON(self, b.GetId(), parent.on_quit)
        
        sizer.AddMany([
            (wx.TextCtrl(self, -1, size = (250, -1), value = "XXX")),
            (b, 0, wx.EXPAND),
            ])
        
        self.SetDefaultItem(b)
        b.SetFocus()

        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        sizer.Fit(self)


class F(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Test Frame")
        panel = P(self)
        self.Fit()

    def on_quit(self, e):
        self.Close(True)


def main():
    app = wx.PySimpleApp()
    f = F()
    f.Show(True)
    app.MainLoop()

if __name__ == "__main__":
    main()
    

Regards,
Cliff

-- 
With your cold flesh, my cold love, hissing not kissing
                            -Siouxsie and the Banshees






More information about the Python-list mailing list