Wxpython Layout Management Part Wx.gridbagsizer Usage example

Source: Internet
Author: User

Text = ("This is text box")
panel = WX. Panel (self,-1)
ChkAll1 = wx. CheckBox (Panel, Id_chkbox_can_sel_all, u ' Select All ')
Chkknown = wx. CheckBox (Panel, Id_chkbox_can_unknown, U ' not ')
Chkunknow = wx. CheckBox (Panel, Id_chkbox_can_known, U ' will ')

ChkAll2 = wx. CheckBox (Panel, Id_chkbox_segment_sel_all, u ' Select All ')
Chkchuzhong = wx. CheckBox (Panel, Id_chkbox_segment_sel_chuzhong, U ' Junior High School ')
Chkcollegue = wx. CheckBox (Panel, Id_chkbox_segment_sel_daxue, U ' university ')
ChkCollegueCet6 = wx. CheckBox (Panel, Id_chkbox_segment_sel_daxue_cet6, U ' University level six ')

#lst = wx. Listctrl (panel, Id_list_recite, Style=wx. Lc_report|wx. Lc_virtual|wx. Lc_hrules|wx. Lc_vrules)
Self.lst = Recitelistctrl (panel, Id_list_recite)

SZ1 = wx. Gridsizer (rows=2, cols=4, vgap=5, hgap=20)
Sz1. ADD (CHKALL1)
Sz1. ADD (Chkknown)
Sz1. ADD (Chkunknow)
Sz1. ADD (WX. Textctrl (panel))

Sz1. ADD (CHKALL2)
Sz1. ADD (Chkchuzhong)
Sz1. ADD (Chkcollegue)
Sz1. ADD (CHKCOLLEGUECET6)

Sz0 = wx. Boxsizer (WX. VERTICAL)
Sz0. ADD (SZ1)
Sz0. ADD (Self.lst, 1, WX. EXPAND)
Panel. Setsizer (sz0)

Wxpython Layout Management Part Wx.gridbagsizer Usage example

Transferred from: http://www.jbxue.com/python/29629.htm

The Wxpython layout manages the use of Wx.gridbagsizer parts, Wx.gridbagsizer implements explicit positioning of parts, and part projects can be studied together across rows or columns.

The most complex sizer in the WxPython.
It brings an explicit positioning of the part.  Part items can also span rows or columns. Featured Tutorials: Wxpython Chinese Course

Wx. The Gridbagsizer constructor is very simple.
Wx. Gridbagsizer (integer vgap, integer hgap)
Vertical and horizontal blanks (GAP) define the white space distance between the subassemblies. Add a part item to the grid through the Add () method.
ADD (self, item, tuple POS, tuple span=wx. Defaultspan, Integer flag=0,
Integer border=0, Userdata=none)
"Item" refers to the part you want to insert into the grid. POS Specifies the location of the virtual grid. The "POS" value for the upper left Cell is (0, 0). " span is the span value of a corresponding part. For example (3, 2) refers to a part that spans 3 rows and 2 columns. "Flag" and "border" two parameters in earlier WX. The Boxsizer has been discussed.
These part items in the grid can change their size as the window scales, or they can remain unchanged.

You can use these two methods if you want the parts to become larger or smaller.
Addgrowablerow (integer row)
Addgrowablecol (integer col)

Example:

Copy Code code example:

#!/usr/bin/python
#coding =utf-8

#wxgridbagsizer. py

Import WX

Class MyFrame (WX. Frame):
def __init__ (self,parent, ID, title):
Wx. Frame.__init__ (self, parent, ID, title, WX.) Defaultposition)
Sizer = WX. Gridbagsizer (9, 9)
Sizer. ADD (WX. button (self,-1, "button 1"), (0, 0), WX. Defaultspan,
Wx. All, 5)
Sizer. ADD (WX. button (self,-1, "button 2"), (1, 1), (1, 7), WX. EXPAND)
Sizer. ADD (WX. button (self,-1, "button 3"), (6, 6), (3, 3), WX. EXPAND)
Sizer. ADD (WX. button (self,-1, "button 4"), (3, 0), (1, 1),
Wx. Align_center)
Sizer. ADD (WX. button (self,-1, "button 5"), (4, 0), (1, 1),
Wx. Align_left)
Sizer. ADD (WX. button (self,-1, "button 6"), (5, 0), (1, 1),
Wx. Align_right)
Sizer. Addgrowablerow (6)
Sizer. Addgrowablecol (6)
Self. Setsizerandfit (Sizer)
Self. Centre ()
Class MyApp (WX. APP):
def OnInit (self):
frame = MyFrame (None,-1, ' wxgridbagsizer.py ')
Frame. Show (True)
Return True
App = MyApp (0)
App. Mainloop ()

To implement a component that spans more than one cell, you must provide WX. EXPAND logo.
Self. Setsizerandfit (Sizer)
This method is similar to Setsizer (), and it will advertise the size to the window to ensure that all the buttons are displayed on the window.

Wxpython Layout Management Part Wx.gridbagsizer Usage example

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.