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/hbox3 = wx.BoxSizer(wx.HORIZONTAL)tc2 = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE)hbox3.Add(tc2, 1, wx.EXPAND)vbox.Add(hbox3, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)vbox.Add((-1, 25))hbox4 = wx.BoxSizer(wx.HORIZONTAL)cb1 = wx.CheckBox(panel, -1, 'Case Sensitive')cb1.SetFont(font)hbox4.Add(cb1)cb2 = wx.CheckBox(panel, -1, 'Nested Classes')cb2.SetFont(font)hbox4.Add(cb2, 0, wx.LEFT, 10)cb3 = wx.CheckBox(panel, -1, 'Non-Project classes')cb3.SetFont(font)hbox4.Add(cb3, 0, wx.LEFT, 10)vbox.Add(hbox4, 0, wx.LEFT, 10)vbox.Add((-1, 25))hbox5 = wx.BoxSizer(wx.HORIZONTAL)btn1 = wx.Button(panel, -1, 'Ok', size=(70, 30))hbox5.Add(btn1, 0)btn2 = wx.Button(panel, -1, 'Close', size=(70, 30))hbox5.Add(btn2, 0, wx.LEFT | wx.BOTTOM , 5)vbox.Add(hbox5, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)panel.SetSizer(vbox)self.Centre()self.Show(True)app = wx.App()GoToClass(None, -1, 'Go To Class')app.MainLoop()<strong>The</strong> layout is straitforward. We create one vertical sizer. We put then five horizontalsizers into it.font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)font.SetPointSize(9)<strong>The</strong> default system font was 10px. On my platform, it was too big for this kind ofwindow. So I set the font size to 9px.vbox.Add(hbox3, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)vbox.Add((-1, 25))We already know that we can control the distance among widgets by combining theflag parameter with the border parameter. But there is one real constraint. In theAdd() method we can specify only one border for all given sides. In our example, wegive 10px to the right and to the left. But we cannot give 25 px to the bottom. Whatwe can do is to give 10px to the bottom, or 0px. If we omit wx.BOTTOM. So if weneed different values, we can add some extra space. With the Add() method, we caninsert widgets and space as well.vbox.Add(hbox5, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)We place the two buttons on the right side of the window. How do we do it? Threethings are important to achieve this. <strong>The</strong> proportion, the align flag and thewx.EXPAND flag. <strong>The</strong> proportion must be zero. <strong>The</strong> buttons should not change theirsize, when we resize our window. We must not specify wx.EXPAND flag. <strong>The</strong> buttons6 de 17 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!