wxButton and wxBoxSizer

Hi:

I try to add buttons in sub windows, but it looks like doesn't work.
I expect the buttons can show vertically in self.banner_box, but the only
one I can see is the first 'Pass' button. What's wrong with my code?

Thanks.

···

----------------------------------------------------------------------------
------------

from wxPython.wx import *
from wxPython.ogl import *

class A_Frame(wxFrame):

    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                         wxPoint(0,0), wxSize(1024, 720))
        self.SetBackgroundColour(wxWHITE)
        self.CreateStatusBar()

        game_menu= wxMenu()
        game_menu.Append(101, 'Exit')

        menu_bar = wxMenuBar()
        menu_bar.Append(game_menu, 'Game')
        self.SetMenuBar(menu_bar)

        EVT_MENU(self, 101, self.game_menu_exit)

        self.SetAutoLayout(True)
        self.banner_box = wxWindow(self, -1, wxPyDefaultPosition,
wxPyDefaultSize, wxRAISED_BORDER)
        self.banner_box.SetBackgroundColour('blue')
        lc = wxLayoutConstraints()
        lc.top.SameAs(self, wxTop, 10)
        lc.right.PercentOf(self, wxRight, 50)
        lc.bottom.SameAs(self, wxBottom, 10)
        lc.left.SameAs(self, wxLeft, 10)
        self.banner_box.SetConstraints(lc)

        box=wxBoxSizer(wxVERTICAL)
        self.button_pass = wxButton(self.banner_box, 1000, "Pass")
        self.button_resign=wxButton(self.banner_box, 1001, "Resign")
        self.button_score=wxButton(self.banner_box, 1002, "Score")
        self.button_undo=wxButton(self.banner_box, 1003, "Undo")
        box.Add(self.button_pass, 0, wxEXPAND)
        box.Add(self.button_resign, 0, wxEXPAND)
        box.Add(self.button_score, 0, wxEXPAND)
        box.Add(self.button_undo, 0, wxEXPAND)
        box.Fit(self.banner_box)
        self.banner_box.SetSizer(box)

        self.Show(true)

    def game_menu_exit(self, event):

        self.Close(true)

class App(wxApp):
    def OnInit(self):
        frame = A_Frame(NULL, -1, "Game")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

if __name__ == '__main__':

   wxOGLInitialize()
   app = App(0)
   app.MainLoop()

Frank Chen wrote:

Hi:

I try to add buttons in sub windows, but it looks like doesn't work.
I expect the buttons can show vertically in self.banner_box, but the only
one I can see is the first 'Pass' button. What's wrong with my code?

Change banner_box to be a wxPanel instead of a wxWindow. The wxWindow
class does not support autolayout for various reasons (although it is
simple to add in a derived class if desired.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!