Wxpython window layout-proportion/flag/border parameter description, wxpythonproportion

Source: Internet
Author: User

Wxpython window layout-proportion/flag/border parameter description, wxpythonproportion

The new wxpython learning has been entangled in the formatting of window controls. After several days of Data Query and experiment, it is summarized as follows.

1. You need an instance. The window has three rows of controls.

The first line is a text prompt (the size remains unchanged, the text is left aligned, and the control is left ).

The second line is the text prompt (the control is left, the size remains unchanged, the text is left-aligned, the text is centered vertically,), the text input box (the control is left, the size is horizontally scaled to the right, vertical Scaling), buttons (the control is right, the right side is fixed, and the size is scaled to the left side), buttons (the control is right, and the size remains unchanged ).

Multi-line text box in the third line (control extension, size expansion in four directions until the remaining space is fully occupied)

 

# Coding = UTF-8

Import wx

Class MyFrame (wx. Frame ):
Def _ init _ (self, parent, id ):
Wx. Frame. _ init _ (self, parent, id, u'test Panel ', size = (400,300 ))

# Create a panel
Panel = wx. Panel (self)
# Create open and save buttons
Self. bt_open = wx. Button (panel, label = 'open ')
Self. bt_save = wx. Button (panel, label = 'save ')
# Create text, align left, and expand freely
Self. st_tips = wx. StaticText (panel, 0, u "Enter the file path", style = wx. ALIGN_LEFT | wx. EXPAND)
Self. st_tips2 = wx. StaticText (panel, 0, u "file path:", style = wx. ALIGN_LEFT | wx. EXPAND)
Self. text_filename = wx. TextCtrl (panel, style = wx. ALIGN_LEFT)
# Create a text content box with multiple lines and vertical scroll bars
Self. text_contents = wx. TextCtrl (panel, style = wx. TE_MULTILINE | wx. HSCROLL)

# Add a container. The controls in the container are arranged horizontally and side by side.
Bsizer_top = wx. BoxSizer (wx. VERTICAL)
# Add a container. The controls in the container are arranged vertically and horizontally.
Bsizer_center = wx. BoxSizer (wx. HORIZONTAL)
Bsizer_bottom = wx. BoxSizer (wx. HORIZONTAL)

# Add the st_tips control to the container. proportion = 0 indicates that when the container size changes, the size of the st_tips control remains unchanged.
# Flag = wx. EXPAND | wx. in ALL, wx. ALL indicates that the white space with the width of x is added around the st_tips control. The value of x is the value of the border parameter. In this example, It is border = 5.
# Wx. EXPAND indicates that the st_tips control occupies full space.
Bsizer_top.Add (self. st_tips, proportion = 0, flag = wx. EXPAND | wx. ALL, border = 5)
# Proportion = 1 indicates the size change of the st_tips2 control when the container size changes. The change speed is 1.
Bsizer_center.Add (self. st_tips2, proportion = 0, flag = wx. ALL | wx. ALIGN_CENTER_VERTICAL | wx. ALIGN_LEFT, border = 5)
# Proportion = 2 indicates the size change of the text_filename control when the container size changes. The modification speed is 2.
Bsizer_center.Add (self. text_filename, proportion = 2, flag = wx. EXPAND | wx. ALL, border = 5)
Bsizer_center.Add (self. bt_open, proportion = 1, flag = wx. ALL, border = 5)
Bsizer_center.Add (self. bt_save, proportion = 0, flag = wx. ALL, border = 5)

Bsizer_bottom.Add (self. text_contents, proportion = 1, flag = wx. EXPAND | wx. ALL, border = 5)

# Wx. VERTICAL horizontal segmentation
Bsizer_all = wx. BoxSizer (wx. VERTICAL)
# Add the top sizer. proportion = 0 indicates that the bsizer_top size cannot be changed.
Bsizer_all.Add (bsizer_top, proportion = 0, flag = wx. EXPAND | wx. ALL, border = 5)
Bsizer_all.Add (bsizer_center, proportion = 0, flag = wx. EXPAND | wx. ALL, border = 5)
# Add the top sizer. proportion = 1 indicates the bsizer_bottom size change.
Bsizer_all.Add (bsizer_bottom, proportion = 1, flag = wx. EXPAND | wx. ALL, border = 5)
Self. Bind (wx. EVT_BUTTON, self. onOpen, self. bt_open)
# Self. Bind (wx. EVT_BUTTON, self. OnCloseMe, button)

Panel. SetSizer (bsizer_all)


Def onOpen (self, event ):
Self. text_contents.AppendText (str (self. GetSizeTuple ()))
Self. text_contents.AppendText (str (self. bt_open.GetSizeTuple ()))
Self. text_contents.AppendText (str (self. text_filename.GetSizeTuple ()))
Self. SetSize (700,600 ))
Self. text_contents.AppendText (str (self. GetSizeTuple ()))
Self. text_contents.AppendText (str (self. bt_open.GetSizeTuple ()))
Self. text_contents.AppendText (str (self. text_filename.GetSizeTuple ()))


If _ name _ = '_ main __':
App = wx. PySimpleApp ()
Frame = MyFrame (parent = None, id =-1)
Frame. Show ()
Frame. Center ()
App. MainLoop ()
3. Conclusion 1: Box = wx. BoxSizer (integer orient)

Orientation Parameters, Indicating the control arrangement, wx. VERTICAL arrangement, wx. HORIZONTAL arrangement

One aspect of the image is: the former is three, the horizontal is three 1, the latter is 111, and the vertical is three 1

 

2. sizer. Add (wx. Window window Window, integer proportion = 0, integer flag = 0, integer border = 0)

Window Parameters: Indicates the control to be added.

 

Roportion Parameters: The proportion of space occupied by the added control in the orientation defined by the positioning method.

Assume that there are three buttons with a ratio of 0, 1, and 2 respectively. They have been added to a horizontal wx. BoxSizer with a width of 30 and the start width is 10.

When the width of sizer is changed from 30 to 60, the width of Button 1 remains unchanged, and it is still 10. The width of Button 2 is about (10 + (60-30) * 1/(1 + 2) = 30, and the button 2 is about 20.

Not strictly speaking, button 2 occupies 1/3 of the increment, And button 3 occupies 2/3 of the increment.

 

Border Parameters: Controls the margin of the added control, that is, to add some pixels between parts.

The border parameter works with the flag parameter. To apply the border parameter, You need to define which side uses the border in the flag parameter. For example, flag = wx. RIGHT indicates that the RIGHT margin is border width.

 

Flag parameters:

As described above, the flag parameter and the border parameter are combined to specify the margin width, Including the following options:

Wx. LEFT, LEFT margin
In addition, the flag parameter can be combined with the proportion parameter to specify the alignment (Arrangement) mode of the control., Including the following options:
The flag parameter can use the wx. EXPAND flag. The added control occupies all available space in the direction of the sizer positioning.

Above.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.