wxBoxSizers in window and two embedded panels.

Donnal Walter donnal at donnal.net
Mon Apr 21 10:36:13 EDT 2003


Igor Prischepoff wrote:
> Hi!
>  Sorry for my english, i'm not native english speaking man.
>  Recently switched to python and it's wonderful wxPython toolkit.
>  Having trouble with wxBoxSizer.
>  I want this heirarchy
> 
>       wxWindow (a must! i've don't need to attach panels to wxFrame directly.)
>        /    \
>     Panel2  Panel1
>     
> Panel1 and panel2 must occupy all available screen space on window1.
> Trouble is: they don't.
>     
> 
>  ------------------------------  -----
>  !  panel2                     !      !
>  !-----------------------------!      !
>  !  panel1                     !      !
>  !                             !      !
>  ------------------------------!      !
>  !                 window1            !
>  !------------------------------------

See if this code does what you want. Remember that wxPanel is derived 
from wxWindow.

#!/usr/bin/env python
from wxPython.wx import *

class MyPanel(wxPanel):
     def __init__(self, parent):
         # create panel (the outer window)
         wxPanel.__init__(self, parent, id=-1)
         # create the inner panels
         panel1 = wxPanel(self, -1)
         panel2 = wxPanel(self, -1)
         panel2.SetBackgroundColour("BLUE")
         panel1.SetBackgroundColour("RED")

         # create the sizer
         sizer = wxBoxSizer(wxVERTICAL)

         # add panels to sizer
         sizer.Add(panel1, 1, wxEXPAND)
         sizer.Add(panel2, 1, wxEXPAND)

         # enable sizers
         self.SetSizer(sizer)
         self.SetAutoLayout(1)
         sizer.Fit(self)
         sizer.SetSizeHints(self)

class MyFrame(wxFrame):
     def __init__(self):
         wxFrame.__init__(self, None, -1, 'Sizer Demo',
                          size=(400,200))
         outerWin = MyPanel(self)
         outerWin.SetBackgroundColour("BLACK")

class MyApp(wxApp):
     def OnInit(self):
         frame = MyFrame()
         frame.Show(1)
         return 1

if __name__ == '__main__':

     app = MyApp(0)
     app.MainLoop()







More information about the Python-list mailing list