[wxPython] wxNotebook

Hi,

I am programming a wxFrame to open a window with a wxNoteBook inside.
The wxNotebook is composed of a thumb index and two pages ,"Page 1" and
"Page 2". In Page 1, there is a wxCtrlText ,which contains the word
'hello' and in Page 2, there is a wxButton "OK".
I am using wxLayoutConstraints to assign to the wxCtrlText, the width of
40 percent and the height of 20 percent of the main frame, and to centre
the button "OK" in the main frame.

The problem is :
when I modify the window's size with the size grip, the size und the
position of the elements stay the same. What can I do to force them to
change their size in the same way?

thanks for your help,
Graziella

···

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

from wxPython.wx import *

wxID_TESTFRAME = NewId()
ID_Name = NewId()
ID_BUTTON = NewId()

class MyFrame(wxFrame):
   def __init__(self, parent):

        self._init_ctrls(parent)
        self._initConstraints()

   def _init_ctrls(self, parent):
        wxFrame.__init__(self, parent, wxID_TESTFRAME, 'test',
                          size = wxSize(500, 300))

        self.CreateStatusBar()

        self.nb = wxNotebook(self, -1)
        self.SetAutoLayout(true)
        global win1
        win1 = wxWindow(self.nb, -1)
        self.text_Name = wxTextCtrl(win1, ID_Name, "Hello", wxPoint(120,
55), wxSize(110, 20))
        self.nb.AddPage(win1, "Page 1")

        global win2
        win2 = wxWindow(self.nb, -1)
        self.buttonOK = wxButton(win2, ID_BUTTON, "OK")
        self.nb.AddPage(win2, "Page 2")

   def _initConstraints(self):

        c = wxLayoutConstraints()
        c.left.SameAs(win1, wxLeft,40)
        c.centreY.SameAs(win1, wxCentreY)
        c.width.PercentOf(win1, wxWidth,40)
        c.height.PercentOf(win1, wxHeight,20)
        self.text_Name.SetConstraints(c)
        #------------------------------------
        c = wxLayoutConstraints()
        c.left.AsIs()
        c.bottom.AsIs()
        c.right.AsIs()
        c.height.AsIs()
        self.nb.SetConstraints(c)
        #------------------------------------
        c = wxLayoutConstraints()
        c.left.AsIs()
        c.bottom.AsIs()
        c.right.AsIs()
        c.height.AsIs()
        win1.SetConstraints(c)
        #------------------------------------
        c = wxLayoutConstraints()
        c.centreX.SameAs(win2, wxCentreX)
        c.centreY.SameAs(win2, wxCentreY)
        c.width.AsIs()
        c.height.AsIs()
        self.buttonOK.SetConstraints(c)
        #-----------------------------------
        c = wxLayoutConstraints()
        c.left.AsIs()
        c.bottom.AsIs()
        c.right.AsIs()
        c.height.AsIs()
        win2.SetConstraints(c)

        self.Layout()

class MyApp(wxApp):
   def OnInit(self):
        frame = MyFrame(None)
        frame.Show(true)
        self.SetTopWindow(frame)
        return(true)
app = MyApp(0)
app.MainLoop()

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

The problem is :
when I modify the window's size with the size grip, the size und the
position of the elements stay the same. What can I do to force them to
change their size in the same way?

This probably has something to do with it:

        #------------------------------------
        c = wxLayoutConstraints()
        c.left.AsIs()
        c.bottom.AsIs()
        c.right.AsIs()
        c.height.AsIs()
        self.nb.SetConstraints(c)

You are telling the notebook to never change its size or position. If you
want it to fill the frame you probably want this:

        c = wxLayoutConstraints()
        c.left.SameAs(self, wxLeft)
        c.bottom.SameAs(self, wxBottom)
        c.right.SameAs(self, wxRight)
        c.top.SameAs(self, wxTop)
        self.nb.SetConstraints(c)

Your other constraints may need modified too.

You should probably look into using Sizers instead, they are much easier.
Plus you can use wxDesigner to create the code for using them.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users