Transferred from: http://wwty.iteye.com/blog/385519
Wx. Boxsizer:
Python code
- box = WX. Boxsizer (integer orient)
The orientation can be wx. VERTICAL or WX. Horizontal
Python code
- Box. ADD (WX. Window window, integer proportion=0, Integer flag = 0, Integer border = 0)
Parameter interpretation:
1, proportion:
The proportion parameter defines the proportion of the component's space in the given direction, relative to the other components
For example: We have three buttons, the values of proportion are 0,1,2 respectively. The three buttons are placed in the horizontal Sizer, button with proportion 0 is not the change in all. However, the Button with proportion 2 will be twice times larger than the one with proportion 1 in horizontal position.
Python code
- Import WX
- Class Border (WX. Frame):
- def __init__ (self, parent, ID, title):
- Wx. Frame.__init__ (self, parent, ID, title, size= (+ ))
- panel = WX. Panel (self,-1,size= (+))
- Panel. Setbackgroundcolour (' white ')
- Boxsizer1 = wx. Boxsizer (WX. VERTICAL)
- BTN1 = wx. Button (Panel,-1, ' Botton1 ')
- BTN2 = wx. Button (Panel,-1, ' Botton2 ')
- Btn3 = wx. Button (Panel,-1, ' Botton3 ')
- Boxsizer1. ADD (btn1, proportion=0, Flag=wx. EXPAND, border=0)
- Boxsizer1. ADD (BTN2, proportion=1, flag=wx. All, border=0)
- Boxsizer1. ADD (Btn3, proportion=2, flag=wx. All, border=0)
- Self . Setsizer (Boxsizer1)
- Self . Centre ()
- Self . Show (True)
- App = WX. APP ()
- Border (None,-1, ')
- App. Mainloop ()
This example can be used to observe the effect of the proportion parameter.
2. Flag:
The flag parameter can use ' | ' To produce a combination of multiple flags.
The flag parameter defines two main behaviors:
The first parameter is the border of the window: This parameter determines the width of the border, which determines the event where a border is added to one side of the window.
Another parameter determines the behavior of the Sizer event, and when Sizer changes, the space is allocated. And how much of the allocation depends on a particular kind of sizer is used.
3, border:
Determines the border width, if the flag parameter is set to include any border flag
Finally, special note:
Flag and border parameters are used together.
VBox. ADD (Midpan, 1, WX. EXPAND | Wx. All, 20)
Flag=wx. EXPAND | Wx. All,border=20---------This represents the Midpan this component will make full use of space, but will be reserved from around 20px as border. So if we say that WX is used. EXPAND flag, instead of setting border, our component will take full advantage of the allocated space.
Finally, we can also define the adjustment of our components. However, this adjustment refers to an adjustment within the space allocated by the Sizer to the current component.
We do it with the following flags:
Wx. Align_left
Wx. Align_right
Wx. Align_top
Wx. Align_bottom
Wx. Align_center_vertical
Wx. Align_center_horizontal
Wx. Align_center
Take a look at the following example:
Python code
- hbox5 = wx. Boxsizer (WX. Horizontal)
- btn1 = wx. button (Panel, -1, 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)
This example places the existing hbox5 into VBox when total, while wx. Align_right's role is to place the hbox5 in the Sizer.
The following are the common flag parameters:
1. These flags is used to specify which side (s) of the Sizer item, the border width would apply to.
- Wx. TOP
- Wx. BOTTOM
- Wx. Left
- Wx. Right
- Wx. All
2. The item is expanded to fill the space allotted to the item.
Wx. EXPAND
There are two other not listed, if used, you can check the Help document
Finally, there are some cases where we need to add some blank areas to our application, and we can use the following code:
Python code
- VBox = wx. Boxsizer (WX. VERTICAL)
- VBox. ADD ((-1, + ))
VBox. Add (( -1))---added 25 pixels of empty space
Wx. Boxsizer