Python
  Home arrow Python arrow Page 3 - Organization in wxPython
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 
Moblin 
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

Organization in wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2005-06-29

    Table of Contents:
  • Organization in wxPython
  • Box Sizers
  • Box Sizers Continued
  • Grid Bag Sizers

  • 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

    Organization in wxPython - Box Sizers Continued


    (Page 3 of 4 )

    Of course, what if we do choose to size it proportinally? Let's take a look:

    from wxPython.wx import *

    class SizerFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Sizers' )

          self.panel = wxPanel ( self, -1 )
          self.text = wxStaticText ( self.panel, -1, 'Just some text. That is all. I promise.' )
          self.button1 = wxButton ( self.panel, -1, 'Click Me' )
          self.button2 = wxButton ( self.panel, -1, 'Me as well.' )
          self.sizer = wxBoxSizer ( wxVERTICAL )
          self.sizer.Add ( self.text, 1  )
          self.sizer.Add ( self.button1, 4 )
          self.sizer.Add ( self.button2, 6 )
          self.panel.SetSizerAndFit ( self.sizer )
          self.SetClientSize ( self.panel.GetSize() )

          self.Show ( True )

    application = wxPySimpleApp()
    window = SizerFrame()
    application.MainLoop()

    Now let's play around with the third argument. Execute this application:

    from wxPython.wx import *

    class SizerFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Sizers' )

          self.panel = wxPanel ( self, -1 )
          self.text = wxStaticText ( self.panel, -1, 'Just some text. That is all. I promise.' )
          self.button1 = wxButton ( self.panel, -1, 'Click Me' )
          self.button2 = wxButton ( self.panel, -1, 'Me as well.' )
          self.sizer = wxBoxSizer ( wxVERTICAL )
          self.sizer.Add ( self.text, 1, wxGROW  )
          self.sizer.Add ( self.button1, 4, wxGROW )
          self.sizer.Add ( self.button2, 6, wxGROW )
          self.panel.SetSizerAndFit ( self.sizer )
          self.SetClientSize ( self.panel.GetSize() )

          self.Show ( True )

    application = wxPySimpleApp()
    window = SizerFrame()
    application.MainLoop()

    Resize the window a bit and notice the behavior of the controls. Let's now change wxGROW to wxSHAPED:

    from wxPython.wx import *

    class SizerFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Sizers' )

          self.panel = wxPanel ( self, -1 )
          self.text = wxStaticText ( self.panel, -1, 'Just some text. That is all. I promise.' )
          self.button1 = wxButton ( self.panel, -1, 'Click Me' )
          self.button2 = wxButton ( self.panel, -1, 'Me as well.' )
          self.sizer = wxBoxSizer ( wxVERTICAL )
          self.sizer.Add ( self.text, 1, wxSHAPED  )
          self.sizer.Add ( self.button1, 4, wxSHAPED )
          self.sizer.Add ( self.button2, 6, wxSHAPED )
          self.panel.SetSizerAndFit ( self.sizer )
          self.SetClientSize ( self.panel.GetSize() )

          self.Show ( True )

    application = wxPySimpleApp()
    window = SizerFrame()
    application.MainLoop()

    Again, resize the window and notice the behavior of the controls.

    It is also possible to nest box sizers within one another. A good use for this would be centering a control – or another sizer – in a frame. First, we would create a vertical sizer and add a space with a proportion of 1. I'll show you how to add a space in the example. It's not hard at all. Next we would add a horizontal sizer to the vertical sizer. To the horizontal sizer we would add a space, our control and another space. Both spaces would have a proportion of 1, and the control would have a proportion of 0 ( unless you really wanted to resize it ). The horizontal sizer itself would have a proportion of 0. Finally, another space would be added to the vertical sizer. This may sound complicated, but it's very simple when put into code:

    from wxPython.wx import *

    class SizerFrame ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Sizers' )

          self.panel = wxPanel ( self, -1 )
          self.horizontal = wxBoxSizer ( wxHORIZONTAL )
          self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )
          self.horizontal.Add ( wxStaticText ( self.panel, wxID_ANY, 'Centered.' ) )
          self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )
          self.vertical = wxBoxSizer ( wxVERTICAL )
          self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )
          self.vertical.Add ( self.horizontal, 0, wxALIGN_CENTER )
          self.vertical.Add ( ( 0, 0 ), 1, wxEXPAND )
          self.panel.SetSizerAndFit ( self.vertical )

          self.Show ( True )

    application = wxPySimpleApp()
    window = SizerFrame()
    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 5 hosted by Hostway