How To Create TextControl in wxPython

In this wxPython article i want to show you How To Create TextControl in wxPython. so a text control allows text to be displayed and edited. It may be single line or multi-line. Notice that a lot of methods of the text controls are found in the base wx.TextEntry class which is a common base class for wx.TextCtrl and other controls using a single line text entry field (e.g. wx.ComboBox).

 

 

 

 

Also you can check More GUI Development Tutorials in the below link.

1: PyQt5 GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Pyside2 GUI Development Tutorials 

4: Kivy GUI Development Tutorials

 

 

 

 Window Styles

This class supports the following styles:

  • wx.TE_PROCESS_ENTER: The control will generate the event wxEVT_TEXT_ENTER (otherwise pressing Enter key is either processed internally by the control or used to activate the default button of the dialog, if any).
  • wx.TE_PROCESS_TAB: Normally, TAB key is used for keyboard navigation and pressing it in a control switches focus to the next one. With this style, this won’t happen and if the TAB is not otherwise processed (e.g. by wxEVT_CHAR event handler), a literal TAB character is inserted into the control. Notice that this style has no effect for single-line text controls when using wxGTK.
  • wx.TE_MULTILINE: The text control allows multiple lines. If this style is not specified, line break characters should not be used in the controls value.
  • wx.TE_PASSWORD: The text will be echoed as asterisks.
  • wx.TE_READONLY: The text will not be user-editable.
  • wx.TE_RICH: Use rich text control under MSW, this allows having more than 64KB of text in the control. This style is ignored under other platforms.
  • wx.TE_RICH2: Use rich text control version 2.0 or higher under MSW, this style is ignored under other platforms
  • wx.TE_AUTO_URL: Highlight the URLs and generate the TextUrlEvents when mouse events occur over them.
  • wx.TE_NOHIDESEL: By default, the Windows text control doesn’t show the selection when it doesn’t have focus – use this style to force it to always show it. It doesn’t do anything under other platforms.
  • wx.TE_LEFT: The text in the control will be left-justified (default).
  • wx.TE_CENTRE: The text in the control will be centered (wxMSW, wxGTK, wxOSX).
  • wx.TE_RIGHT:  So The text in the control will be right-justified (wxMSW, wxGTK, wxOSX).

 

 

 

 

So this is the complete code for How To Create TextControl in wxPython

 

 

 

 

At the top we have created our MyFrame.  this class is a top level window that inherits from wx.Frame and we create the object of our MyPanel class in here.

 

 

 

 

 

After that we have created our MyPanel class that inherits from wx.Panel. and we create our TextCtrl in this class.

 

 

 

 

 

These are the different kinds of TextControl in wxPython

 

 

 

 

 

So the last class is MyApp class that inherits from wx.App. the OnInit() method is where you will most often create frame subclass objects. passes to wxPython. Unlike procedural programs, a wxPython GUI program primarily responds to the events taking place around it, mostly determined by a human user clicking with a mouse and typing at the keyboard. When all the  frames in an application have been closed, the app.MainLoop() method will return and the program will exit.

 

 

 

 

 

So run the code and this will be the result

How To Create TextControl in wxPython
How To Create TextControl in wxPython

 

 

 

 

 

Also you can watch the complete video for this article

Share via
Copy link
Powered by Social Snap