[wxPython-users] newbie question on auto sizing
Christopher Barker
Chris.Barker at noaa.gov
Tue Jan 9 10:44:54 PST 2007
NOTE:
In general, it's better to enclose code, rather than inlining it -- =
mailers tend to mangle whitespace.
I've enclosed a version that works. I changed a bunch of minor stuff =
(much of it for style, really), but the big change is that it creates =
the sizer, then add the buttons, then calls panel.SetSizerAndFit(Sizer).
You could probably have done it the way you originally had it, if you =
had called self.panel.Fit() after adding the buttons.
Note that I got rid of your explicit size for the buttons -- that's what =
sizers are for!
-Chris
-- =
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 at noaa.gov
-------------- next part --------------
#!/usr/bin/env python
import wx
class Pallet(wx.Frame):
def __init__(self, *args, **kwargs):
super(Pallet, self).__init__(*args, **kwargs)
self.panel =3D wx.Panel(self)
self.ButtonSizer =3D wx.BoxSizer(wx.HORIZONTAL)
self.createButtons()
self.panel.SetSizerAndFit(self.ButtonSizer)
self.Fit()
=
def buttonLabels(self):
return ("Button1", "Button2", "Button3")
=
def createButtons(self):
labels=3D self.buttonLabels()
#buttonSize=3D(70,30)
sizer=3Dself.ButtonSizer
for label in labels:
button =3D wx.Button(self.panel, label=3Dlabel)#, size=3Dbutton=
Size)
sizer.Add(button, 0, wx.ALIGN_CENTER|wx.ALL, 2)
=
class MyApp(wx.App):
def OnInit(self):
pallet =3D Pallet(None, style=3Dwx.FRAME_TOOL_WINDOW)
pallet.Show()
return True
=
if __name__ =3D=3D '__main__':
app =3D MyApp(0)
app.MainLoop()=20
More information about the wxpython-users
mailing list