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
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.
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
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.