13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Layout management in <strong>wxPython</strong>http://www.zetcode.com/wxpython/layout/self.Bind(wx.EVT_MENU, self.OnClose, id=1)sizer = wx.BoxSizer(wx.VERTICAL)self.display = wx.TextCtrl(self, -1, '', style=wx.TE_RIGHT)sizer.Add(self.display, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)gs = wx.GridSizer(4, 4, 3, 3)gs.AddMany( [(wx.Button(self, -1, 'Cls'), 0, wx.EXPAND),(wx.Button(self, -1, 'Bck'), 0, wx.EXPAND),(wx.StaticText(self, -1, ''), 0, wx.EXPAND),(wx.Button(self, -1, 'Close'), 0, wx.EXPAND),(wx.Button(self, -1, '7'), 0, wx.EXPAND),(wx.Button(self, -1, '8'), 0, wx.EXPAND),(wx.Button(self, -1, '9'), 0, wx.EXPAND),(wx.Button(self, -1, '/'), 0, wx.EXPAND),(wx.Button(self, -1, '4'), 0, wx.EXPAND),(wx.Button(self, -1, '5'), 0, wx.EXPAND),(wx.Button(self, -1, '6'), 0, wx.EXPAND),(wx.Button(self, -1, '*'), 0, wx.EXPAND),(wx.Button(self, -1, '1'), 0, wx.EXPAND),(wx.Button(self, -1, '2'), 0, wx.EXPAND),(wx.Button(self, -1, '3'), 0, wx.EXPAND),(wx.Button(self, -1, '-'), 0, wx.EXPAND),(wx.Button(self, -1, '0'), 0, wx.EXPAND),(wx.Button(self, -1, '.'), 0, wx.EXPAND),(wx.Button(self, -1, '='), 0, wx.EXPAND),(wx.Button(self, -1, '+'), 0, wx.EXPAND) ])sizer.Add(gs, 1, wx.EXPAND)self.SetSizer(sizer)self.Centre()self.Show(True)def OnClose(self, event):self.Close()app = wx.App()GridSizer(None, -1, 'GridSizer')app.MainLoop()Notice how we managed to put a space between the Bck and the Close buttons. Wesimply put an empty wx.StaticText there. Such tricks are quite common.In our example we used the AddMany() method. It is a convenience method foradding multiple widgets at one time.AddMany(list items)Widgets are placed inside the table in the order, they are added. <strong>The</strong> first row is filledfirst, then the second row etc.wx.FlexGridSizerThis sizer is similar to wx.GridSizer. It does also lay out it's widgets in a twodimensional table. It adds some flexibility to it. wx.GridSizer cells are of the samesize. All cells in wx.FlexGridSizer have the same height in a row. All cells have thesame width in a column. But all rows and columns are not necessarily the sameheight or width.wx.FlexGridSizer(int rows=1, int cols=0, int vgap=0, int hgap=0)rows and cols specify the number of rows and columns in a sizer. vgap and hgap addsome space between widgets in both directions.Many times developers have to develop dialogs for data input and modification. I findwx.FlexGridSizer suitable for such a task. A developer can easily set up a dialog10 de 17 27/04/2008 1:03

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!