I've been using wx Python and sizers for years, and sizers
still baffle me.
They only do what I expect about 30% of the time, and I usually
end up trying random changes for several hours and then giving
up on the last 20% of what I'm trying to accomplish.
Is there any good documentation on wx sizers?
I've found the stuff on the wxpython wiki, but all that has is
a list of what sorts of sizers there are. There are no
examples and no usage information. The wxWidgets documentation
pages aren't helpful. The descriptions of what the flags/styles
do are so vaugue you might as well just skip the descriptions
and try them to see what happens.
Here's short example:
1 #!/usr/bin/python
2 import wx
3
4 class MyFrame(wx.Frame):
5 def __init__(self, parent, title):
6 wx.Frame.__init__(self, parent, -1, title)
7 panel = wx.Panel(self)
8 vsizer = wx.BoxSizer(wx.VERTICAL)
9
10 hsizer = wx.BoxSizer(wx.HORIZONTAL)
11
12 hsizer.Add(wx.StaticText(panel,-1,'Left'))
13
14 hs = wx.BoxSizer(wx.HORIZONTAL)
15 hs.Add(wx.StaticText(panel,-1,'CenterL'))
16 hs.Add(wx.StaticText(panel,-1,'CenterR'),flag=wx.LEFT,border=10)
17 hsizer.Add(hs,1,flag=wx.ALIGN_CENTER)
18
19 hsizer.Add(wx.StaticText(panel,-1,'Right'))
20
21 vsizer.Add(hsizer,1,flag=wx.ALL+wx.EXPAND,border=10)
22
23 vsizer.Add(wx.StaticText(panel,-1,'Centered',style=wx.ALIGN_CENTER),1,flag=wx.EXPAND)
24 panel.SetSizerAndFit(vsizer)
25 panel.Layout()
26 vsizer.Fit(self)
27
28 class MyApp(wx.App):
29 def OnInit(self):
30 frame = MyFrame(None, "Baffled by Sizers")
31 frame.Show(True)
32 self.SetTopWindow(frame)
33 return True
34
35 app = MyApp(False)
36 app.MainLoop()
What I expect is something like this:
Left CenterL CenterR Right
Centered
What I get after resizign the window is
Left Right
CenterL CenterR
Centered
Question 1: Why is the hbox containing "CenterL CenterR" not
centered? Doesn't line 17 says to center it? How
do I get the (CenterL CenterR) centered?
Question 2: Why are the three things in the first hbox (Left,
(CenterL CenterR), Right) not aligned vertically?
All I'm trying to do is create a horizontal sizer containing
three things: one left justified, one centered, one right
justified. I've spend hours messing with sizers, andthere just
doesn't seem to be any way to do it.
···
--
Grant Edwards grante Yow! Let me do my TRIBUTE
at to FISHNET STOCKINGS...
visi.com