[Python] WxPython edit Box Component Learning Summary (original)

Source: Internet
Author: User

1, Summary 1, commonly used 4 kinds of editing frame construction

1. Normal edit box

      

Single-line Input simple edit box (? For the object that is in the same box)

Self.textbox = wx. Textctrl (parent =?)

2. Password edit box

      

Asterisks disguise the Password box for the input character

Self.textbox = wx. Textctrl (parent =?, style = Wx.te_password)

3. Read-Only text box

      

You cannot change content, but you can copy a read-only text box

Self.textbox = wx. Textctrl (parent =?, style = wx.te_readonly, value = "I am a read-only text box")

When we want to modify the content, we can: self. Textbox.setvalue ("String")

4, Multi-line text box

      

text box with multiple lines of input (single line length exceeds non-wrap)

Self.textbox =wx. Textctrl (parent =?, style = Wx.te_multiline)

(single line exceeds line wrap, horizontal scroll bar)

Self.textbox =wx. Textctrl (parent =?, style = Wx.te_multiline|wx. HScroll

2. Event Binding

Self.textBox.Bind (event type, corresponding function)

Common event types are:

     

3. Style when edit box is constructed

The constructor of the Textctrl class is as follows:

Wx. Textctrl (parent, ID, value, pos, size, style)

Value: Text in the edit box

POS: The position of the edit box in the window

Size: Edit box sizes

Style: Edit box's styling parameters

Common parameters accepted by style

     

2, detailed

PS: The main talk in the summary is commonly used to, the general common things on the above is enough.

Next is the detailed type parameters and methods of the Textctrl.

1, WxPython in WX. Constructors for the Textctrl class:

    

Wx. Textctrl (
Parent, ID, value= ', pos=wx. Defaultpostion, Size=wx. DefaultSize, Style=0, validator=wx. Defaultvalidator, Name=wx. Textctrlnamestr
)

2, WX. Style parameters for Textctrl

3. Function to modify the text in the edit box method

4. Use multiple lines or Rich text styles

Wx. HScroll: If the text control is multiline, and if the style is declared, the long row will not wrap and the horizontal scroll bar is displayed. This option is ignored in GTK +. Wx.te_auto_url: If the Rich Text option is set and the platform supports it, this style causes an event to be generated when the user's mouse is over a URL in the text or when it is tapped on that URL. The alias of the Wx.TE_DONTWRAP:wx.HSCROLL. Wx.te_linewrap: For a line that is too long, wrap the line as a character. Some operating systems may ignore this style. Wx.te_multiline: The text control will display multiple lines. Wx.te_rich: Used for Windows, Rich text controls are used as basic widgets. This allows the use of style text. WX.TE_RICH2: For Windows, use the latest version of Rich text controls as a basic widget. Wx.te_wordwrap: For a line that is too long, wrap the word as a line. This style is ignored by many operating systems.

5, in WX. Textctrl the Text style class in the Widgets (WX. Textattr Class)

constructor function:

Wx. Textattr (Coltext, colback=wx. Nullcolor, Font=wx. Nullfont)

Coltext: Font Color

Colback: Background color

Font: Fonts

Text and background colors are Wxpython objects that can be specified by the color name or RGB value of the color (red, green, blue). Both Nullcolor and Nullfont represent the current default values.

Wx. Methods of the Textattr class:

6, WX. Some practical methods of the Textctrl class are:

7. Response Text Event:

We need to use it when we bind the event. Bind () function. Its constructor:

Frame. Bind (event type, frame. Ontext, text)

Among the event types are:

Evt_text: This event occurs when the text in the control changes. This event is generated because the text is changed by the user's input or by using SetValue () in the program. Evt_text_enter: This event occurs when the user presses the ENTER key in a wx.te_process_enter-style text control. Evt_text_url: If the Wx.te_rich or WX.TE_RICH2 style is set on a Windows system, and the Wx.te_auto_url style is set, a mouse event occurs on the URL within the text control, The event is triggered. Evt_text_maxlen: If the maximum length of the control is specified with Setmaxlength (), the event is triggered when the user tries to enter a longer string. You might use this, for example, to display a warning message to the user.
3. Impressions

The edit box component itself is relatively simple to use, but generally works with the layout manager (WX. Boxsizer Class) and tags (wx. Statictext Class) combined with the use of.

Reference: http://justcoding.iteye.com/blog/914125

4. Operation effect

  

5. Sample Code

PS: This code can reflect the general content of the edit box (the content of this article) and the layout manager (WX. Boxsizer Class) and tags (wx. Statictext Class) Simple application

 1 #coding: Utf-8 2 #author: Twobox 3 4 Import WX 5 6 class Mywin (WX.         Frame): 7 def __init__ (self, Parent, title): 8 Super (Mywin, self). __init__ (parent, title = title) 9 10 Create a panel on the #在 window frame all panel = WX. Panel (self) #创建 vertical dimension Manager: Used to manage the next level manager and other components VBox = WX. Boxsizer (WX. VERTICAL) #创建 level manager hbox1, label, normal edit box (bound content Change event), and put the latter on hbox1 hbox1 = wx. Boxsizer (WX. Horizontal) Stctext1 = wx. Statictext (panel, id =-1, label = "text box:") self.t1 = wx. Textctrl (panel) Self.t1.Bind (WX. Evt_text, self. onkeytyped) Hbox1. ADD (stctext1, proportion = 0, flag = wx. Expand|wx. All, border = 5) hbox1. ADD (self.t1, proportion = 1, flag = WX. Expand|wx. All, border = 5) #创建 level manager hbox2, label, password edit box (set to a large length of 6) (bound text length over-limit event), and put the latter on the hbox2 Hbox2 = wx. Boxsizer (WX. Horizontal) StcText2 = wx. Statictext (panel, id =-1, label = "Password box:") Self.t2 = wx. Textctrl (panel, style = Wx.te_password) self.t2.SetMaxLength (6) Self.t2.Bind (WX. Evt_text_maxlen, self. Onmaxlen) Hbox2. ADD (stcText2, proportion = 0, flag = wx. Expand|wx. All, border = 5) to Hbox2. ADD (self.t2, proportion = 1, flag = WX. Expand|wx. All, border = 5) 32 33 # Create a horizontal manager hbox3, label, read-only edit box, and put the latter on hbox3 hbox3 = wx. Boxsizer (WX. Horizontal) StcText4 = wx. Statictext (panel, id =-1, label = "read-only Box:") Self.t4 = wx. Textctrl (panel, style = wx.te_readonly|wx.te_center, value = "I am a read-only text box") PNs Hbox3. ADD (STCTEXT4, proportion = 0, flag = wx. Expand|wx. All, border = 5) hbox3. ADD (SELF.T4, proportion = 1, flag = WX. Expand|wx. All, border = 5) #将 hbox1, Hbox2, Hbox3 added to VBox. ADD (Hbox1, proportion=0, flag=wx. EXPAND | Wx. All, border=0) VBox. ADD (Hbox2, proportion=0, flag=wx. EXPAND | Wx. All, border=0) VBox. ADD (Hbox3, proportion=0, flag=wx. EXPAND | Wx. All, border=0) #创Build a label, multiline text box (BIND press Enter event), and put the two on vbox stcText3 = wx. Statictext (panel, id =-1, label = "Multiline text box", style = WX.) Align_center) Self.t3 = wx. Textctrl (panel, style = Wx.te_multiline) Self.t3.Bind (WX. Evt_text_enter, self. onenterpressed) VBox. ADD (stcText3, proportion = 0, flag = wx. Expand|wx. All, border = 5) VBox. ADD (SELF.T3, proportion = 1, flag = WX. Expand|wx. All, border = 5) The Dimension manager for the panel panels of #设置 is vbox53 panel. Setsizer (vbox) #调整 window frame and displays the self. SetSize ((350,500)). Center (). Show (). Fit () def onkeytyped (Self, event): + Print (event. GetString ()) onenterpressed def (Self, event): + Print ("Enter Pressed") All-in-all Def onmaxlen (self, event) : Print ("Maximum length reached") ("the"): (). App () Mywin (None, "edit box Sample") app. Mainloop () __name__ = = ' __main__ ': Main ()

[Python] wxPython edit Box Component Learning Summary (original)

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.