You can drag and drop the design wxpython form did not find Ruyi after, only the Wxpython learned, a simple project completed, summed up some careful:
- Statictext control changes the contents of the content with the Sellabel method
- The overall layout is Gridbagsizer, because you just have to tell Sizer which row you're inserting a control into, and how many rows you want to go across.
bag=wx. Gridbagsizer (5,5) # Generates a layout control bag with a row and column spacing of 5. ADD (Btn1,pos= (0,0)) #第1行第一列加入一个按钮bag. ADD (Label1,pos= (0,1), Span (1,3), flag=wx. Left|wx. Right|wx. Grow,border=10) #第一行第二列加入一个label, and spans 3 columns, and the left and right margins are 10 pixels, note wx. Left parameters are actually acting on the border parameter, please carefully understand this example #同时根据窗口大小自动填充 (grow equals extend, the only difference is that you can play two words less)
- Row layout with Flexgridsizer
Unfortunately, it is not possible for an element to be streamed like HTML, so even a few simple controls are used for layout controls, otherwise all controls will appear in the (0,0) position if they are absolutely positioned, not positioned, or laid out.
The advantage of Flexgridsizer is that the width of each column can be different, so that as long as the elements are thrown into the lattice, the size of the lattice will be automatically adjusted with the size of the control, which is similar to "flow layout"
Shape like 3rd/8 page First previous next last page of the page bar:
DefGetpager(Self):#工具条所需要的控件: Label and Button pt1=wx. Statictext (self,-1,"section") pt2=wx. Statictext (self,-1,"/") pt3=wx. Statictext (self,-1,"Page") lblpageindex=wx. Statictext (self,-1,"0") lblpagecount=wx. Statictext (self,-1,"0") btnfirst=wx. Bitmapbutton (self,-1,myres.getfirstbitmap (), style=0,size= (15,15))#用图片做按钮, style=0 can make the picture borderless btnlast=wx. Bitmapbutton (self,-1,myres.getlastbitmap (), style=0,size= (15,()) btnprev=wx. Bitmapbutton (self,-1,myres.getprevbitmap (), style=0,size= (15,()) btnnext=wx. Bitmapbutton (self,-1,myres.getnextbitmap (), style=0,size= (15,15)) #生成sizer, throw the control in the     FG=WX. Flexgridsizer (Hgap=2,vgap=2) # The cell interval is 2    GB. ADD (Pt1,0,0) gb. ADD (Lblpageindex,0,1) gb. ADD (Pt2,0,2) gb. ADD (Lblpagecount,0,3) gb. ADD (Pt3,0,4) gb. ADD (Btnfirst,0,5) #如此反复 #比BoxSizer要好用
- About the layout () method:
In many cases, the control content is changed, you need to force call layout method to re-layout, such as the above page bar, 3rd/1506 page, is tightly close together, is actually three label, once you turn to the last page, 3 becomes 1506, you will find that you can not see clearly, because its width is "3 "width, SetLabel () after the layout (), you will find that the width has changed naturally
- About tables and "data sources"
. NET programming comes up with the concept of "data sources"
A large amount of data in the Wxpython is used in the grid, the simplest use is creategrid, and then to the cell assignment, which is obviously not suitable for paging data, the grid can be changed at any time the data inside the grid is settable ()
The key to using the settable () method is to do a "Table", which is what I do:
#-*-Encoding:utf-8-*-Import WXImport Wx.grid#继承wx. Grid.pygridtablebase, then rewrite some of the following necessary methodsClassMyTable(wx.grid.PyGridTableBase):Def__init__(Self,datasource):' [{colname:value,columane:value2 ...}, {colname:value,columane:value2 ...}, ' {col Name:value,columane:value2 ...}, ...] "' wx.grid.pygridtablebase.__init__ (self) self.data={} self.collabels=datasource[0].keys ()#用于生成列头的列表 Self.rows=len (DataSource)#行数 Self.cols=len (datasource[0].keys ())#行数 i=0For Rowin datasource:j=0For K,vin Row.items (): self.data[(i,j)]=str (v)#给每一个单元格赋值的方法 j+=1 i+=1#没必要隔行换色, I do not use the online various ready-made odd and even practice, only set a property: So that the extra-long text does not cross into other cells (the default will cross) self.cell=wx.grid.gridcellattr () Self.cell. Setoverflow (False)# These five is the required methodsDefGetnumberrows(self):Return Self.rwosDefGetnumbercols(self):Return Self.colsDefGetcollabelvalue(Self,col):#列头return Self.collabels[col]#同样你可以实现自己的行头 Getrowlabelvalue, just return the appropriate value.DefIsemptycell(self, Row, col):Return Self.data.get ((row, col))IsNotNoneDefGetValue(self, Row, col):#为网格提供数据 value= self.data.get (row, col)If ValueisNotNone:return valueElseReturn‘‘DefSetValue(self, row, col, value):#给表赋值 self.data[(row,col)]= value# The table can also provide the attribute for each cellDefGetAttr(self, row, col, kind): Attr= Self.cell attr. Incref ()#暂时没看懂Return attr"If you send a data source with no column header information, as follows: [[Value1,value2,value3,...], [Value1,value2,value3,...], [value1,value2,val Ue3,...], ...] The change you need to make is simply to comment out the relevant code for the column header.#使用 gv=wx. Grid ()#插一点Grid的技巧: GV. Setrowlabelsize (20) #默认行头很宽, set, but once set, the width of the wardrobe is not to drag the GV. Enableediting (False)#默认表格是可以全表编辑的, the GV is closed here. Enabledragrowsize (False)#默认表格的每格是可以拖动高度的, the GV is closed here. Setdefaultcelloverflow (False)#貌似没起什么作用, so the Overflow result=myprocess.gettable () dt=mytable is set in the table itself ( Result)#得到数据后转化成我需要的数据源 GV. Cleargrid ()#清空表格 GV. settable (DT) GV. Hide () GV. Show ()#假如gv是之前做的, no column header information, this is the only way I found to refresh the column header, hide and then show ... I hope we have a more reliable approach. Score of
Wxpython Application Experience