Statictext and Textctrl are usually used in WX to display characters. Similar to Static and Edit in MFC. Textctrl can set more properties, but he has a border and a background.
Their default display effect, as shown in the following figure:
The code is as follows:
import wx class MainFrame (WX. Frame): Def __init__ (self, iid=-1, redirect=true, Parent=none, pos=wx. Defaultposition, title= ' RCL Update v1.0 '): # MainFrame WX. Frame.__init__ (self, parent, IID, title, POS, (720), WX. Default_frame_style ^ (WX. Resize_border | Wx. Minimize_box | Wx. Maximize_box)) self. SetLabel (' Python wx statictext and Textctrl Test ') panel = wx. Panel (self) self.statustext = wx. Statictext (Panel,-1, ' Statictext sample ', (m), ()) Self.textctrl = WX. Textctrl (Panel,-1, ' Ctrltext sample ', (m), ()) class Rclapp (WX. APP): # initialization here def OnInit (self): Self.frame = MainFrame () self.frame.Show () s Elf.
Settopwindow (Self.frame) return true # cleanup this def OnExit (self): return true def main (): App = Rclapp () app. Mainloop () if __name__ = = ' __main__ ': Main ()
Many times, we will need multiple lines of display, that is, multiline, from the experimental view, Statictext and Textctrl can support multiline display. In Statictext, if you need more than a row to display, the default will be in the space to switch, and if there is no space characters, the default will not automatically wrap, you need to add ' \ n ' to the line, and Textctrl will be full after a row of the automatic line, do not need white space characters such a hint. The effect is as follows:
The code is as follows:
Import WX class MainFrame (WX. Frame): Def __init__ (self, iid=-1, redirect=true, Parent=none, pos=wx. Defaultposition, title= ' RCL Update v1.0 '): # MainFrame WX. Frame.__init__ (self, parent, IID, title, POS, (720), WX. Default_frame_style ^ (WX. Resize_border | Wx. Minimize_box | Wx. Maximize_box)) self. SetLabel (' Python wx statictext and Textctrl Test ') panel = wx. Panel (self) w,h = self. GetSize () self. SetSize (W, h+50)) Self.statustext = WX. Statictext (Panel,-1, ' tttttttttttttttttttttttttttttttttttttttttt\nkkkkkkkkk ', (), ()) Self.textctrl = WX.
Textctrl (Panel,-1, ' tttttttttttttttttttttttttttttttttttttttttt\nkkkkkkkkk ', (), (), Wx.te_multiline) Class Rclapp (WX. APP): # initialization here def OnInit (self): Self.frame = MainFrame () self.frame.Show () s Elf.
Settopwindow (Self.frame) return True # cleanup here def OnExit (self): Return True def main (): app = Rclapp () app.
Mainloop () if __name__ = = ' __main__ ': Main ()
Constructor reference for Statictext:
Http://www.wxpython.org/docs/api/wx.StaticText-class.html
__init__ (self, parent, id=-1, Label=emptystring, Pos=defaultposition, Size=defaultsize, style=0, name= STATICTEXTNAMESTR)
(constructor)
Constructor reference for Textctrl:
Http://www.wxpython.org/docs/api/wx.TextCtrl-class.html
__init__ (self, parent, id=-1, Value=emptystring, Pos=defaultposition, Size=defaultsize, style=0, validator= Defaultvalidator, NAME=TEXTCTRLNAMESTR)
(constructor)
Many times we want to have Textctrl display effects, such as multi-line display, such as scroll bar, but we do not want to have board, different background, here with the help of some of the Textctrl property settings, can achieve similar results. The effect is as follows:
The code is as follows:
Import WX class MainFrame (WX. Frame): Def __init__ (self, iid=-1, redirect=true, Parent=none, pos=wx. Defaultposition, title= ' RCL Update v1.0 '): # MainFrame WX. Frame.__init__ (self, parent, IID, title, POS, (720), WX. Default_frame_style ^ (WX. Resize_border | Wx. Minimize_box | Wx. Maximize_box)) self. SetLabel (' Python wx statictext and Textctrl Test ') panel = wx. Panel (self) w,h = self. GetSize () self. SetSize (W, h+50)) Self.statustext = WX. Statictext (Panel,-1, ' tttttttttttttttttttttttttttttttttttttttttt\nkkkkkkkkk ', (), ()) Self.textctrl = WX. Textctrl (Panel,-1, ' TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\NKKKKKKKKK ', (MB), (m), Wx.te_readonly | wx . te_multiline | Wx. Border_none | Wx. brushstyle_transparent) Self.textCtrl.SetBackgroundColour (panel. Backgroundcolour) class Rclapp (WX. APP): # initialization here def OnInit (self): Self.frame = MainFrame() Self.frame.Show () self.
Settopwindow (Self.frame) return true # cleanup this def OnExit (self): return true def main (): App = Rclapp () app.
Mainloop () if __name__ = = ' __main__ ': Main ()
More Statictext and Textctrl property settings can refer to:
Http://www.cnblogs.com/ankier/archive/2012/09/17/2689364.html
http://justcoding.iteye.com/blog/904217