wxPython控件学习之wx.BoxSizer
wx.BoxSizer:
1.构造函数 boxSizer = wx.BoxSizer(integer orient) orient可以是wx.VERTICAL or wx.HORIZONTAL
2.向sizer里面增加一个控件。box.Add(wx.Window window, integer proportion=0, integer flag = 0, integer border = 0)
主要参数:
1.proportion:proportion参数定义了构件在既定方向上所占空间的比例,是相对的,相对于其他组件
2、flag:
常用的flag参数:
调整对其方式的flag:
wx.ALIGN_LEFT
wx.ALIGN_RIGHT
wx.ALIGN_TOP
wx.ALIGN_BOTTOM
wx.ALIGN_CENTER_VERTICAL
wx.ALIGN_CENTER_HORIZONTAL
wx.ALIGN_CENTER
- wx.TOP, wx.BOTTOM, wx.LEFT, wx.RIGHT, wx.ALL
#------------------------------------------------------------------------------- # Name: 1 # Purpose: # # Author: ankier # # Created: 13/09/2012 # Copyright: (c) ankier 2012 # Licence: <your licence> #------------------------------------------------------------------------------- import wx class Border(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size =(800,600)) pane = wx.Panel(self, -1, size =(800,600)) pane.SetBackgroundColour('yellow') boxsizer = wx.BoxSizer(wx.HORIZONTAL) btn1 = wx.Button(pane, -1, 'Botton1') btn2 = wx.Button(pane, -1, 'Botton2') btn3 = wx.Button(pane, -1, 'Botton3') boxsizer.Add(btn1, proportion=0, flag=wx.ALL, border=2) boxsizer.Add(btn2, proportion=1, flag=wx.ALL, border=2) boxsizer.Add(btn3, proportion=2, flag=wx.ALL, border=2) self.SetSizer(boxsizer) self.Centre() self.Show(True) def main(): app = wx.App() Border(None, -1, '') app.MainLoop() if __name__ == '__main__': main()