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/wx.BoxSizer. Apart from wx.BoxSizer-s we use wx.GridSizer-s as well. <strong>The</strong>wx.GridSizer will be explained in the next section. Well, there is not much to explain,since the usage of the wx.GridSizer is pretty straightforward.sizer4 = wx.GridSizer(2, 2, 2, 2)sizer4.Add(wx.Button(panel4, -1, 'Find', size=(120, -1)))sizer4.Add(wx.Button(panel4, -1, 'Replace/Find', size=(120, -1)))sizer4.Add(wx.Button(panel4, -1, 'Replace', size=(120, -1)))sizer4.Add(wx.Button(panel4, -1, 'Replace All', size=(120, -1)))In our example the wx.GridSizer is very useful. We need four buttons of the same sizein a particular panel. It is a job for wx.GridSizer, since it organizes all widgets in agrid of cells. Those cells all have the same size and the same width.wx.GridSizerwx.GridSizer lays out widgets in two dimensional table. Each cell within the table hasthe same size.wx.GridSizer(int rows=1, int cols=0, int vgap=0, int hgap=0)In the constructor we specify the number of rows and columns in the table. And thevertical and horizontal space between our cells.In our example we create a skeleton of a calculator. It is a perfect example forwx.GridSizer.Figure: GridSizer example#!/usr/bin/python# gridsizer.pyimport wxclass GridSizer(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(300, 250))menubar = wx.MenuBar()file = wx.Menu()file.Append(1, '&Quit', 'Exit Calculator')menubar.Append(file, '&File')self.SetMenuBar(menubar)9 de 17 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!