[wxpython] StaticBoxSizer problems

M

Matthias Kluwe

Hi!

I'd like to place several StaticBoxes in a frame, but I can't get it
right.

Consider the following code:

import wx

app = wx.PySimpleApp()
frame = wx.Frame(parent=None, title="Test")
box = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(box)
upper_box = wx.StaticBox(parent=frame, label="Upper Box")
box.Add(item=upper_box, flag=wx.GROW)
upper_sizer = wx.StaticBoxSizer(upper_box)
upper_sizer.Add(wx.Button(parent=frame, label="Button"))
frame.Show()
app.MainLoop()

This should show a frame containing a StaticBox which contains a
button, but: The button is not placed within the StaticBox. Hmm.

Additionally: wx.StaticBoxSizer.__init__.__doc__ says that a
StaticBoxSizer is created by __init__(self, StaticBox box, int
orient=HORIZONTAL). But if I change the line

upper_sizer = wx.StaticBoxSizer(upper_box)

to

upper_sizer = wx.StaticBoxSizer(StaticBox=upper_box)

I get the error: TypeError: new_StaticBoxSizer() takes at least 1
argument (0 given).

What am I missing?

Regards,
Matthias
 
S

Steve Holden

Matthias said:
Hi!

I'd like to place several StaticBoxes in a frame, but I can't get it
right.

Consider the following code:

import wx

app = wx.PySimpleApp()
frame = wx.Frame(parent=None, title="Test")
box = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(box)
upper_box = wx.StaticBox(parent=frame, label="Upper Box")
box.Add(item=upper_box, flag=wx.GROW)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You should remiove this line.
upper_sizer = wx.StaticBoxSizer(upper_box)
upper_sizer.Add(wx.Button(parent=frame, label="Button"))
frame.Show()
app.MainLoop()

This should show a frame containing a StaticBox which contains a
button, but: The button is not placed within the StaticBox. Hmm.

Additionally: wx.StaticBoxSizer.__init__.__doc__ says that a
StaticBoxSizer is created by __init__(self, StaticBox box, int
orient=HORIZONTAL). But if I change the line

upper_sizer = wx.StaticBoxSizer(upper_box)

to

upper_sizer = wx.StaticBoxSizer(StaticBox=upper_box)

I get the error: TypeError: new_StaticBoxSizer() takes at least 1
argument (0 given).

What am I missing?
Generally speaking what you appear to be missing is a methodical
approach to GUI consruction. This reminds me of a lot of my early
experiments with wxPython code :)

Less is more, but it *does* take a while to get the hang of sizers and
the like.

regards
Steve
 
M

Matthias Kluwe

Hi!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You should remiove this line.

Hmm. As I see it, this means constructing the StaticBox and not placing
it in the frame. Obviously, this does not help.
[...]
What am I missing?

Generally speaking what you appear to be missing is a methodical
approach to GUI consruction. This reminds me of a lot of my early
experiments with wxPython code :)

"a methodical approach to GUI construction"? Please be more specific --
any hints are welcome. Clearly, the above is an experiment with
wxPython, not anything methodical. This may follow when I understand
how StaticBoxSizer works.

Regards,
Matthias
 
M

Matthias Kluwe

Hi!

If anybody's interested, I've got an solution now.
I'd like to place several StaticBoxes in a frame, but I can't get it
right.
import wx
app = wx.PySimpleApp()
frame = wx.Frame(parent=None, title="Test")
box = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(box)
upper_box = wx.StaticBox(parent=frame, label="Upper Box")
box.Add(item=upper_box, flag=wx.GROW)
upper_sizer = wx.StaticBoxSizer(upper_box)

Oops. That's a thinko. upper_box is no sizer. The right line must be

box.Add(item=upper_sizer, flag=wx.GROW)
upper_sizer.Add(wx.Button(parent=frame, label="Button"))
frame.Show()
app.MainLoop()

Additionally: wx.StaticBoxSizer.__init__.__doc__ says that a
StaticBoxSizer is created by __init__(self, StaticBox box, int
orient=HORIZONTAL). But if I change the line
upper_sizer = wx.StaticBoxSizer(upper_box)

upper_sizer = wx.StaticBoxSizer(StaticBox=upper_box)
I get the error: TypeError: new_StaticBoxSizer() takes at least 1
argument (0 given).

This is still to be solved.

Regards,
Matthias
 
S

Steve Holden

Matthias said:
Hi!




Hmm. As I see it, this means constructing the StaticBox and not placing
it in the frame. Obviously, this does not help.
Did you actually try removing the line and running the program? Guess
what: the button appears inside the static box sizer. And your problem
with that would be ... ?
[...]

What am I missing?

Generally speaking what you appear to be missing is a methodical
approach to GUI consruction. This reminds me of a lot of my early
experiments with wxPython code :)


"a methodical approach to GUI construction"? Please be more specific --
any hints are welcome. Clearly, the above is an experiment with
wxPython, not anything methodical. This may follow when I understand
how StaticBoxSizer works.
Well, "methodical" would seem to include testing the suggestions of
well-meaning fellow netizens, for a start, rather than using your
psychic powers to predict results.

regards
Steve
 
M

Matthias Kluwe

Hi!

Steve said:
Did you actually try removing the line and running the program?

I tried, of course :) Removing the line

box.Add(item=upper_box, flag=wx.GROW)

yields the remaining program

import wx

app = wx.PySimpleApp()
frame = wx.Frame(parent=None, title="Test")
box = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(box)
upper_box = wx.StaticBox(parent=frame, label="Upper Box")
upper_sizer = wx.StaticBoxSizer(upper_box)
upper_sizer.Add(wx.Button(parent=frame, label="Button"))
frame.Show()
app.MainLoop()
Guess what: the button appears inside the static box sizer. And your problem
with that would be ... ?

.... the StaticBox not being displayed.
Well, "methodical" would seem to include testing the suggestions of
well-meaning fellow netizens, for a start, rather than using your
psychic powers to predict results.

No prediction needed :) I can't see how I have suggested you're not
well-meaning.

Regards,
Matthias
 
S

Steve Holden

Matthias said:
Hi!




I tried, of course :) Removing the line

box.Add(item=upper_box, flag=wx.GROW)

yields the remaining program

import wx

app = wx.PySimpleApp()
frame = wx.Frame(parent=None, title="Test")
box = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(box)
upper_box = wx.StaticBox(parent=frame, label="Upper Box")
upper_sizer = wx.StaticBoxSizer(upper_box)
upper_sizer.Add(wx.Button(parent=frame, label="Button"))
frame.Show()
app.MainLoop()




... the StaticBox not being displayed.
But the StaticBox *is* displayed when I run the program under Windows,
at least. What platform are you running on?
No prediction needed :) I can't see how I have suggested you're not
well-meaning.
I didn't take any such inference from your response. I am slightly
confused that the program doesn't run for you, however. Here's the exact
source I ran:

import wx

app = wx.PySimpleApp()
frame = wx.Frame(parent=None, title="Test")
box = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(box)
upper_box = wx.StaticBox(parent=frame, label="Upper Box")
#box.Add(item=upper_box, flag=wx.GROW)
upper_sizer = wx.StaticBoxSizer(upper_box)
upper_sizer.Add(wx.Button(parent=frame, label="Button"))
box.Add(upper_sizer, flag=wx.GROW)
frame.Show()
print "running"
app.MainLoop()

The upper_box is displayed because it's presented as an argument to the
StaticBoxSizer's creator.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top