A Close Look at wxPython Controls

Controls are, obviously, essential to your wxPython applications. They allow you to gather input from the user so that you can make decisions based on that input. Let’s take a close look at a few controls availible to you and your applications. This article will cover wxChoice, wxComboBox, wxListBox and wxTextCtrl. It is the third one in a series about wxPython.

wxChoice

Here is how a basic wxChoice control is put into an application:

wxChoice ( self, -1, choices = [ 'A', 'B', 'C', 'D' ] )

Note that self is the parent, and -1 is the same as wxID_ANY. The list we provide at the end is, of course, the list of options availible to the user. Let’s put our control in an application so that we can work with it:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.choice = wxChoice ( self.panel, -1, choices = [ 'Choice A', 'Choice B', 'Choice C', 'Choice D' ] )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

Currently, nothing is selected on default. However, suppose we want the second option to be selected on default. We can do this with wxChoice’s SetSelection method. It accepts one argument, which is the position it should start at. “Choice A” is 0, and it increments from there. Let’s force “Choice B” to be selected:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.choice = wxChoice ( self.panel, -1, choices = [ 'Choice A', 'Choice B', 'Choice C', 'Choice D' ] )

      self.choice.SetSelection ( 1 )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

What if, however, we don’t know the position of the string we want to select? This is easily solved. Let’s select “Choice C” without directly passing its position:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.choice = wxChoice ( self.panel, -1, choices = [ 'Choice A', 'Choice B', 'Choice C', 'Choice D' ] )

      positionC = self.choice.FindString ( ‘Choice C’ )

      self.choice.SetSelection ( positionC )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

The GetString method is the opposite of FindString. It accepts a position and returns the string in that position:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.choice = wxChoice ( self.panel, -1, choices = [ 'Choice A', 'Choice B', 'Choice C', 'Choice D' ] )

      stringC = self.choice.GetString ( 2 )

      positionC = self.choice.FindString ( stringC )

      self.choice.SetSelection ( positionC )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

We can manipulate the items in the list using a variety of methods:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.choice = wxChoice ( self.panel, -1, choices = [ 'Choice A', 'Choice B', 'Choice C', 'Choice D' ] )

      # Delete an item ( “Choice A” )

      self.choice.Delete ( 0 )

      # Delete everything

      self.choice.Clear()

      # Add a few choices back

      self.choice.Append ( ‘Choice E’ )

      self.choice.Append ( ‘Choice F’ )

      self.choice.Append ( ‘Choice G’ )

      # Replace a  choice ( “Choice F” )

      self.choice.SetString ( 1, ‘Choice X’ )

      # Count the items

      itemNum = self.choice.GetCount()

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

Finally, we are left with the task of extracting what the user selected. This is extremely simple, fortunately:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.choice = wxChoice ( self.panel, -1, choices = [ 'Choice A', 'Choice B', 'Choice C', 'Choice D' ] )

      self.button = wxButton ( self.panel, 100, ‘Submit’ )

      EVT_BUTTON ( self.panel, 100, self.click )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.sizer.Add ( self.button, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

   def click ( self, event ):

      # Display the position of the selection

      print self.choice.GetSelection()

      # Display the selection

      print self.choice.GetStringSelection()

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

You can also use EVT_COMBOBOX, which calls the function passed to it when the user selects a new option.

{mospagebreak title=wxComboBox and wxListBox}

The wxComboBox and wxListBox controls are similar to wxChoice. The three controls share many methods. Let’s take a quick look at the two controls and compare them with wxChoice:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      # Create the wxChoice control

      self.choice = wxChoice ( self.panel, -1, choices = [ 'A', 'B', 'C', 'D' ] )

      # Create the wxComboBox control

      self.combo = wxComboBox ( self.panel, -1, ‘0’, choices = [ '1', '2', '3', '4' ] )

      # Create the wxListBox control

      self.list = wxListBox ( self.panel, -1, choices = [ 'I', 'II', 'III', 'IV' ] )

      # Append an option to each control

      self.choice.Append ( ‘E’ )

      self.combo.Append ( ‘5’ )

      self.list.Append ( ‘V’ )

      # Delete an option from each control

      self.choice.Delete ( 0 )

      self.combo.Delete ( 0 )

      self.list.Delete ( 0 )

      # Replace choices

      self.choice.SetString ( 1, ‘X’ )

      self.combo.SetString ( 1, ‘X’ )

      self.list.SetString ( 1, ‘X’ )

      # Count items

      self.choice.itemNum = self.choice.GetCount()

      self.combo.itemNum = self.combo.GetCount()

      self.list.itemNum = self.list.GetCount()

      # Add a button

      self.button = wxButton ( self.panel, 100, ‘Click’ )

      EVT_BUTTON ( self.panel, 100, self.click )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.choice, 0 )

      self.sizer.Add ( self.combo, 0 )

      self.sizer.Add ( self.list, 0 )

      self.sizer.Add ( self.button, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

   def click ( self, event ):

      # Display the position of all selections

      print self.choice.GetSelection(), self.combo.GetSelection(), self.list.GetSelection()

      # Display the selection

      print self.choice.GetStringSelection(), self.combo.GetStringSelection(), self.list.GetStringSelection()

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

The wxComboBox and wxListBox controls, however, do contain additional methods that you may use. First, we will tackle wxComboBox. As you know, wxComboBox provides the user with both a list and a text box. If you played around with the last example a bit, you probably saw that the GetStringSelection method will not return values that the user has typed in. Since GetSelection will return -1, however, it is easy to work around this:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.combo = wxComboBox ( self.panel, -1, choices = [ '1', '2', '3', '4' ] )

      self.button = wxButton ( self.panel, 100, ‘Click’ )

      EVT_BUTTON ( self.panel, 100, self.click )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.combo, 0 )

      self.sizer.Add ( self.button, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

   def click ( self, event ):

      if self.combo.GetSelection() == -1:

         self.combo.userValue = self.combo.GetValue()

      else:

         self.combo.userValue = self.combo.GetStringSelection()

      print self.combo.userValue

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

{mospagebreak title=wxListBox is versatile}

The wxListBox control supports multiple selections. We must handle this differently as well:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.list = wxListBox ( self.panel, -1, choices = [ '1', '2', '3', '4' ], style = wxLB_MULTIPLE )

      self.button = wxButton ( self.panel, 100, ‘Click Me…now.’ )

      EVT_BUTTON ( self.panel, 100, self.click )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.list, 0 )

      self.sizer.Add ( self.button, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

   def click ( self, event ):

      selections = self.list.GetSelections()

      if len ( selections ) > 1:

         for selection in selections:

            print ‘Multiple Selected:’, self.list.GetString ( selection )

      else:

         print ‘Single Selected:’, self.list.GetString ( selections [ 0 ] )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

We can insert a whole list of items rather than one at a time, and we can also reset the list entirely, without using Clear:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.list = wxListBox ( self.panel, -1, choices = [ '1', '2', '3', '4' ] )

      # Reset it

      self.list.Set ( [ 'Choice 1', 'Choice 2', 'Choice 3', 'Choice 4' ] )

      # Add some more items

      self.list.InsertItems ( [ 'Choice 5', 'Choice 6', 'Choice 7', 'Choice 8', 'Choice 9', 'Choice 10' ], 4 )

      self.lilst.InsertItems ( [ 'Choice 0' ], 0 )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.list, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

Finally, let’s look at some events:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.list = wxListBox ( self.panel, 100, choices = [ 'One', 'Two', 'Three', 'Four' ] )

      self.combo = wxComboBox ( self.panel, 200, choices = [ 'Red', 'Blue', 'Green', 'Pink' ] )

      EVT_LISTBOX ( self.panel, 100, self.click)

      EVT_LISTBOX_DCLICK ( self.panel, 100, self.listDouble )

      EVT_COMBOBOX ( self.panel, 200, self.click )

      EVT_TEXT_ENTER ( self.panel, 200, self.comboEnter )

      EVT_TEXT ( self.panel, 200, self.comboText )

      self.sizer = wxBoxSizer ( wxVERTICAL )

      self.sizer.Add ( self.list, 0 )

      self.sizer.Add ( self.combo, 0 )

      self.panel.SetSizerAndFit ( self.sizer )

      self.Show ( True )

   def click ( self, event ):

      print ‘Single click.’

   def listDouble ( self, event ):

      print ‘Double click.’

   def comboEnter ( self, event ):

      print ‘You pressed enter in the wxComboBox.’

   def comboText ( self, event ):

      print ‘You changed the text in the wxComboBox.’

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

{mospagebreak title=wxTextCtrl}

You might think that a wxTextCtrl is a simple control, but if you think that, you are very wrong. The wxTextCtrl contains nearly fifty methods. Note that I cannot cover that amount of methods in this article while keeping your interest, so don’t expect me to. Instead, I’ll just cover the more interesting ones.

First, let’s build an application for creating a wxTextCtrl. We’ll use our knowledge from the last article to center the control, and we’ll also throw in a label:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      self.text = wxTextCtrl ( self.panel, -1 )

      self.vertical = wxBoxSizer ( wxVERTICAL )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.vertical.Add ( wxStaticText ( self.panel, wxID_ANY, ‘A Simple wxTextCtrl:’ ), 0, wxALIGN_CENTER )

      self.vertical.Add ( self.text, 0, wxALIGN_CENTER )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal = wxBoxSizer ( wxHORIZONTAL )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.panel.SetSizerAndFit ( self.horizontal )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

When I was learning HTML, one of the things I found interesting was aligning text in a text box. Text can also be aligned in a wxTextCtrl using wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      # Create a left-aligned text box ( default behavior )

      self.text = wxTextCtrl ( self.panel, -1 )

      # Create a centered text box

      self.center = wxTextCtrl ( self.panel, -1, style = wxTE_CENTRE )

      

      # Create a right-aligned text box

      self.right = wxTextCtrl ( self.panel, -1, style = wxTE_RIGHT )

      self.vertical = wxBoxSizer ( wxVERTICAL )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.vertical.Add ( wxStaticText ( self.panel, wxID_ANY, ‘A Simple wxTextCtrl:’ ), 0, wxALIGN_CENTER )

      # Add everything

      self.vertical.Add ( self.text, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.center, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.right, 0, wxALIGN_CENTER )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal = wxBoxSizer ( wxHORIZONTAL )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.panel.SetSizerAndFit ( self.horizontal )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

{mospagebreak title=Password text boxes, read-only text boxes}

Another thing that interested me was creating text boxes for passwords, as well as text boxes that could not be modified. The wxTE_PASSWORD and wxTE_READONLY styles make this possible with the wxTextCtrl. We can also use the SetEditable method:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      # Create a normal text box

      self.text = wxTextCtrl ( self.panel, -1 )

      # Create a password box

      self.passw = wxTextCtrl ( self.panel, -1, style = wxTE_PASSWORD )

      # Create a read-only box

      self.disabled = wxTextCtrl ( self.panel, -1, ‘Cannot be modified.’, style = wxTE_READONLY )

      # Create a read-only box

      self.disabled2 = wxTextCtrl ( self.panel, -1, ‘Nor can this.’ )

      self.disabled2.SetEditable ( False )

      self.vertical = wxBoxSizer ( wxVERTICAL )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.vertical.Add ( wxStaticText ( self.panel, wxID_ANY, ‘A Simple wxTextCtrl:’ ), 0, wxALIGN_CENTER )

      # Add everything

      self.vertical.Add ( self.text, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.passw, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.disabled, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.disabled2, 0, wxALIGN_CENTER )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal = wxBoxSizer ( wxHORIZONTAL )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.panel.SetSizerAndFit ( self.horizontal )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

Multi-line text boxes are also very useful in applications. They can be created from a wxTextCtrl using the wxTE_MULTILINE style, and, optionally, the wxTE_DONTWRAP style:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      # Create a text box

      self.text = wxTextCtrl ( self.panel, -1 )

      # Create a multi-line text box

      self.multi = wxTextCtrl ( self.panel, -1, style = wxTE_MULTILINE )

      # Create a multi-line text box that does not wrap lines

      self.multi2 = wxTextCtrl ( self.panel, -1, style = wxTE_MULTILINE | wxTE_DONTWRAP )

      self.vertical = wxBoxSizer ( wxVERTICAL )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.vertical.Add ( wxStaticText ( self.panel, wxID_ANY, ‘A Simple wxTextCtrl:’ ), 0, wxALIGN_CENTER )

      # Add everything

      self.vertical.Add ( self.text, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.multi, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.multi2, 0, wxALIGN_CENTER )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal = wxBoxSizer ( wxHORIZONTAL )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.panel.SetSizerAndFit ( self.horizontal )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

If we only want the user to be able to enter a certain amount of characters, we can do that with the SetMaxLength method:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      # Create a text box

      self.text = wxTextCtrl ( self.panel, -1 )

      # Create a text box with a maximum length

      self.max = wxTextCtrl ( self.panel, -1 )

      self.max.SetMaxLength ( 10 )

      self.vertical = wxBoxSizer ( wxVERTICAL )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.vertical.Add ( wxStaticText ( self.panel, wxID_ANY, ‘A Simple wxTextCtrl:’ ), 0, wxALIGN_CENTER )

      # Add everything

      self.vertical.Add ( self.text, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.max, 0, wxALIGN_CENTER )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal = wxBoxSizer ( wxHORIZONTAL )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.panel.SetSizerAndFit ( self.horizontal )

      self.Show ( True )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

If we want to trigger an event when the user presses the enter key on his or her keyboard, we can do so with the wxTE_PROCESS_ENTER style and the EVENT_TYPE_TEXT_ENTER_COMMAND event. When the user presses the enter key on our second text box, we’ll write a few characters to the text box. When the user presses the enter key on our third text box, we’ll set the value to something else. We’ll also create two more text boxes. When the user presses the enter key while working with the third text box, its contents will be saved to a file, and the fourth text box will load the contents of that file:

from wxPython.wx import *

class OurFrame ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, ‘wxPython’ )

      self.panel = wxPanel ( self, -1 )

      # Create a text box

      self.text = wxTextCtrl ( self.panel, -1 )

      # Create a text box that triggers an event

      self.enter = wxTextCtrl ( self.panel, 100, style = wxTE_PROCESS_ENTER )

      EVT_TEXT_ENTER ( self.panel, 100, self.handleEnter1 )

      # Create another text box that triggers an event

      self.enter2 = wxTextCtrl ( self.panel, 200, style = wxTE_PROCESS_ENTER )

      EVT_TEXT_ENTER ( self.panel, 200, self.handleEnter2 )

      # Create another text box that triggers an event

      self.save = wxTextCtrl ( self.panel, 300, style = wxTE_PROCESS_ENTER )

      EVT_TEXT_ENTER ( self.panel, 300, self.handleEnter3 )

      # Create another text box that triggers an event

      self.load = wxTextCtrl ( self.panel, -1, style = wxTE_PROCESS_ENTER )

      self.vertical = wxBoxSizer ( wxVERTICAL )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.vertical.Add ( wxStaticText ( self.panel, wxID_ANY, ‘A Simple wxTextCtrl:’ ), 0, wxALIGN_CENTER )

      # Add everything

      self.vertical.Add ( self.text, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.enter, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.enter2, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.save, 0, wxALIGN_CENTER )

      self.vertical.Add ( self.load, 0, wxALIGN_CENTER )

      self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal = wxBoxSizer ( wxHORIZONTAL )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.horizontal.Add ( self.vertical, 0, wxALIGN_CENTER )

      self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

      self.panel.SetSizerAndFit ( self.horizontal )

      self.Show ( True )

   def handleEnter1 ( self, event ):

      self.enter.AppendText ( ‘100%’ )

   def handleEnter2 ( self, event ):

      self.enter2.SetValue ( ‘0%’ )

   def handleEnter3 ( self, event ):

      self.save.SaveFile ( ‘textctrl.txt’ )

      self.load.LoadFile ( ‘textctrl.txt’ )

application = wxPySimpleApp()

window = OurFrame()

application.MainLoop()

Conclusion

Now we know a bit more about the wxChoice, wxComboBox, wxListBox and wxTextCtrl controls, giving us more methods for gathering input from users, which is necessary in any application. We also know that although some wxPython controls seems simple on the surface, such as wxTextCtrl, they can be amazingly complex underneath, containing dozens of methods for us to use.

[gp-comments width="770" linklove="off" ]

antalya escort bayan antalya escort bayan Antalya escort diyarbakir escort