wx.Sizer Issue

I am working through the Getting Started tutorials to learn the syntax
changes since I last built an application with wxPython. About half-way down
the Getting Started page is the section on sizers.

   Emulating that in a new application I'm developing I get an error and I
don't see why. Here are the sizer-related sections of the script (pw.py):

     # Sizers
     outerBox = wx.BoxSizer(wx.VERTICAL) # main container
     unameBox = wx.BoxSizer(wx.HORIZONTAL) # username container
     passwdBox = wx.BoxSizer(wx.HORIZONTAL) # password container
     buttonBox = wx.BoxSizer(wx.HORIZONTAL) # OK and Cancel buttons

   ...

     outerBox.Add(unameBox, 0, wx.ALIGN_CENTER)
     outerBox.Add(passwdBox, 0, wx.ALIGN_CENTER)
     outerBox.Add(buttonBox, 0, wx.ALIGN_CENTER)

     # Layout sizers
     self.SetSizer(self.outerBox)
     self.SetAutoLayout(1)
     self.sizer.Fit(self)
     self.Show()

   When I run the script I get this error:

Traceback (most recent call last):
   File "./pw.py", line 92, in <module>
     frame = MainFrame(None, "PermitWatch")
   File "./pw.py", line 63, in __init__
     self.SetSizer(self.outerBox)
AttributeError: 'MainFrame' object has no attribute 'outerBox'

   I've tried the first line in the Layout sizers section without the second
'self' reference but it makes no difference; the same error message appears.

   This is certainly a simple error on my part but I don't see what it is. A
clue stick is needed.

TIA,

Rich

You have:
outerBox = wx.BoxSizer(wx.VERTICAL) # main container

when you’re trying to SetSizer on self.outerBox

you would need to change that instantiation line to :

self.outerBox = wx.BoxSizer(wx.VERTICAL) # main container

OR the SetSizer call to:

self.SetSizer(outerBox)

···

On Monday, July 7, 2014 2:36:01 PM UTC-7, fuzzydoc wrote:

I am working through the Getting Started tutorials to learn the syntax

changes since I last built an application with wxPython. About half-way down

the Getting Started page is the section on sizers.

Emulating that in a new application I’m developing I get an error and I

don’t see why. Here are the sizer-related sections of the script (pw.py):

 # Sizers

 outerBox = wx.BoxSizer(wx.VERTICAL)    # main container

 unameBox = wx.BoxSizer(wx.HORIZONTAL)  # username container

 passwdBox = wx.BoxSizer(wx.HORIZONTAL) # password container

 buttonBox = wx.BoxSizer(wx.HORIZONTAL) # OK and Cancel buttons

 outerBox.Add(unameBox, 0, wx.ALIGN_CENTER)

 outerBox.Add(passwdBox, 0, wx.ALIGN_CENTER)

 outerBox.Add(buttonBox, 0, wx.ALIGN_CENTER)



 # Layout sizers

 self.SetSizer(self.outerBox)

 self.SetAutoLayout(1)

 self.sizer.Fit(self)

 self.Show()

When I run the script I get this error:

Traceback (most recent call last):

File “./pw.py”, line 92, in

 frame = MainFrame(None, "PermitWatch")

File “./pw.py”, line 63, in init

 self.SetSizer(self.outerBox)

AttributeError: ‘MainFrame’ object has no attribute ‘outerBox’

I’ve tried the first line in the Layout sizers section without the second

‘self’ reference but it makes no difference; the same error message appears.

This is certainly a simple error on my part but I don’t see what it is. A

clue stick is needed.

TIA,

Rich

Thanks, Nathan. I realized this but am stuck at fitting the sizer. Using
self.SetSizerAndFit(outerBox) works while self.sizer.Fit(outerBox) fails.
I'd like to understand why.

Regards,

Rich

···

On Mon, 7 Jul 2014, Nathan McCorkle wrote:

You have:
outerBox = wx.BoxSizer(wx.VERTICAL) # main container

when you're trying to SetSizer on self.outerBox

you would need to change that instantiation line to :
self.outerBox = wx.BoxSizer(wx.VERTICAL) # main container

OR the SetSizer call to:
self.SetSizer(outerBox)

Rich Shepard wrote:

   Thanks, Nathan. I realized this but am stuck at fitting the sizer. Using
self.SetSizerAndFit(outerBox) works while self.sizer.Fit(outerBox) fails.
I'd like to understand why.

"self.sizer" is just the name of the member variable where the author of
the tutorial chose to store his outermost sizer. You chose to store
your outermost sizer in "outerBox". So, you need
    outerBox.Fit(self)

It's just that simple.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.