SunQuest
 
       Python
  Home arrow Python arrow Page 4 - A Close Look at wxPython Controls
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

A Close Look at wxPython Controls
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2005-07-06

    Table of Contents:
  • A Close Look at wxPython Controls
  • wxComboBox and wxListBox
  • wxListBox is versatile
  • wxTextCtrl
  • Password text boxes, read-only text boxes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    A Close Look at wxPython Controls - wxTextCtrl


    (Page 4 of 5 )

    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()

    More Python Articles
    More By Peyton McCullough


     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway