Using wx.BoxSizers in a notebook

Hello list !

I have been coding in python for the past 3 months, i have had some experience with Tkinter, and i decided to switch to wxPython because my project needed a more powerfull GUI toolkit.

I am stuck with a big problem concerning the sizers, which are fairly different from the layout managing in Tkinter. I am able to organize widgets in a simple frame, but i cannot get my example to work.

All i want is to be able to organize widgets on each of my notebook tabs (each tab being a class, herited from a wx.Panel). Here i show only one tab, which i made simple, with a static text, a text field and two panels, which should be organized this way:

···

################
#statTxt txtField #
#lPanel rPanel #
################

I am trying to use BoxSizer, i know a could use the GridSizer, but i still think i should be able to do what i want with this one.

Anyway, here is my code, i would happily read any suggestions.

Cheers,

#############

import wx

class mainWindow(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self,parent,wx.ID_ANY, title=‘Application!’, size=(800,600), pos=(200,100), style=wx.DEFAULT_FRAME_STYLE)

    self.Maximize()
   
    panel=wx.Panel(self, wx.ID_ANY)
    notebook=wx.Notebook(panel)
   
   
    #calling the classes defined here, to create the pages
    self.analyse=analyse(notebook)

   
    #adding them to the notebook
    notebook.AddPage(self.analyse, "Analyse", select=True)
   
   
    sizer=wx.BoxSizer()
    sizer.Add(notebook, 1, wx.EXPAND)
    panel.SetSizer(sizer)
   
    self.Show(True)

class analyse(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent)

    #mainbox that contains all
    self.mainBox=wx.BoxSizer(wx.VERTICAL | wx.EXPAND)
    self.topBox=wx.BoxSizer(wx.HORIZONTAL | wx.EXPAND)
    self.bottomBox=wx.BoxSizer(wx.HORIZONTAL | wx.EXPAND)

   
    ###
    # Create the top box
    ###
   
   
    selLigTxt = wx.StaticText(self, wx.ID_ANY, 'Select')
    selLigFld = wx.TextCtrl(self, wx.ID_ANY)
   
    self.topBox.Add(selLigTxt, 0, wx.ID_ANY | wx.ALL, 5)
    self.topBox.Add(selLigFld, 1, wx.ID_ANY | wx.ALL, 5)
   
   
    ###
    # Create the bottom box
    ###
   
    rightPanel=wx.Panel(self, wx.ID_ANY, style=wx.SUNKEN_BORDER)
    leftPanel=wx.Panel(self, wx.ID_ANY, style=wx.SUNKEN_BORDER)
   
    self.bottomBox.Add(leftPanel, 0, wx.ID_ANY | wx.EXPAND, 5)
    self.bottomBox.Add(rightPanel, 0, wx.ID_ANY | wx.EXPAND, 5)

   
    #Add boxes to the mainBox
    self.mainBox.Add(self.topBox, 0, wx.ALL, 5)
    self.mainBox.Add(self.bottomBox, 0, wx.ALL, 5)
   
   
    #initialize mainSizer
    self.SetSizer(self.mainBox)

app=wx.PySimpleApp()
frame=mainWindow(None,-1,“GUI”)
app.MainLoop()

#################

Thomas Coudrat wrote:

All i want is to be able to organize widgets on each of my notebook tabs
(each tab being a class, herited from a wx.Panel).

note that the notebook has nothing to do with your issue. So I find it easier to just put the Panel on a regular old frame for testing. then try adding your widgets one (or one group) at time, so when something doesn't work, you know where the error is.

Anyway:

        self.bottomBox.Add(leftPanel, 0, wx.ID_ANY | wx.EXPAND, 5)
        self.bottomBox.Add(rightPanel, 0, wx.ID_ANY | wx.EXPAND, 5)

I think this was you key error -- you have told the two panels not to stretch in the direction of the sizer (that 0 option) -- but you want them to. You also don't want o pass in an ID here!

> self.bottomBox.Add(leftPanel, 0, wx.ID_ANY | wx.EXPAND, 5)
> self.bottomBox.Add(rightPanel, 0, wx.ID_ANY | wx.EXPAND, 5)

         self.bottomBox.Add(leftPanel, 1, wx.EXPAND, 5)
         self.bottomBox.Add(rightPanel, 1, wx.EXPAND, 5)

        #Add boxes to the mainBox
        self.mainBox.Add(self.topBox, 0, wx.ALL, 5)
        self.mainBox.Add(self.bottomBox, 0, wx.ALL, 5)

same issue here:

         self.mainBox.Add(self.topBox, 0, wx.ALL, 5)
         self.mainBox.Add(self.bottomBox, 1, wx.ALL|wx.EXPAND, 5)

I cleaned up the code in other ways when trying ot figure this out, so I've enclosed my version.

-Chris

SizerTest.py (1.99 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thomas Coudrat wrote:

Hello list !

I have been coding in python for the past 3 months, i have had some experience with Tkinter, and i decided to switch to wxPython because my project needed a more powerfull GUI toolkit.

I am stuck with a big problem concerning the sizers, which are fairly different from the layout managing in Tkinter. I am able to organize widgets in a simple frame, but i cannot get my example to work.

All i want is to be able to organize widgets on each of my notebook tabs (each tab being a class, herited from a wx.Panel). Here i show only one tab, which i made simple, with a static text, a text field and two panels, which should be organized this way:

################
#statTxt txtField #
#lPanel rPanel #
################

I am trying to use BoxSizer, i know a could use the GridSizer, but i still think i should be able to do what i want with this one.

Anyway, here is my code, i would happily read any suggestions.

Cheers,

In addition to what Chris mentioned, I would recommend checking out the sizer tutorials on the wiki: SizerTutorials - wxPyWiki

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

__________ Information from ESET NOD32 Antivirus, version of virus signature database 3986 (20090403) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com