Home arrow Python arrow Page 2 - Organization Methods Beyond Sizers

Using Tabs for Navigation - Python

A well-designed application will have its widgets organized neatly so that a user can easily access them. To accomplish this, we can use sizers to organize widgets, making them easier to locate and use. However, there are more methods of organization beyond sizers. This article will introduce you to methods of organization that work in conjunction with sizers and such, so you can organize your widgets even more, further benefitting those who use your applications.

TABLE OF CONTENTS:
  1. Organization Methods Beyond Sizers
  2. Using Tabs for Navigation
  3. Using a List for Navigation
  4. Using a Drop-Down List for Navigation
  5. Boxing in Controls
By: Peyton McCullough
Rating: starstarstarstarstar / 6
August 15, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Using tabs for navigation is not unlike switching panels to navigate through sets of widgets. Each tab represents an individual panel, and the panel currently displayed is switched when a tab is pressed. The widget responsible for the arrangement of tabs is wxNotebook. Tabs are created by simply adding pages to the wxNotebook. Let's create some panels and test out the widget:

from wxPython.wx import *

# Create the main window

class Window ( wxFrame ):

   def __init__ ( self ):

      wxFrame.__init__ ( self, None, -1, 'Frame title.' )

      # Create a wxNotebook

      self.notebook = wxNotebook ( self, -1 )

      self.Show ( True )

# Create a panel

class Panel1 ( wxPanel ):

   def __init__ ( self, parent ):

      wxPanel.__init__ ( self, parent, -1 )

      # Put a label in the panel

      self.label = wxStaticText ( self, -1, 'This is the first panel.', pos = ( 25, 25 ) )

# Create another panel

class Panel2 ( wxPanel ):

   def __init__ ( self, parent ):

      wxPanel.__init__ ( self, parent, -1 )

      # Add a few buttons

      self.button1 = wxButton ( self, -1, 'This is a button.', pos = ( 5, 5 ) )

      self.button2 = wxButton ( self, -1, 'So is this.', pos = ( 30, 30 ) )

      self.button3 = wxButton ( self, -1, 'And this.', pos = ( 25, 60 ) )

# Create yet another panel

class Panel3 ( wxPanel ):

   def __init__ ( self, parent ):

      wxPanel.__init__ ( self, parent, -1 )

      # Add a few text boxes

      self.text1 = wxTextCtrl ( self, -1, pos = ( 5, 5 ) )

      self.text2 = wxTextCtrl ( self, -1, pos = ( 5, 50 ), style = wxTE_MULTILINE )

      self.text3 = wxTextCtrl ( self, -1, pos = ( 30, 25 ), style = wxTE_PASSWORD )

application = wxPySimpleApp()

frame = Window()

# Create the panels

instance1 = Panel1 ( frame.notebook )

instance2 = Panel2 ( frame.notebook )

instance3 = Panel3 ( frame.notebook )

# Add the panels

frame.notebook.AddPage ( instance1, 'Panel One' )

frame.notebook.AddPage ( instance2, 'Panel Two' )

frame.notebook.AddPage ( instance3, 'Panel Three' )

application.MainLoop()

As you can see, it's very simple to create a wxNotebook widget and populate it with panels. When the user clicks a tab, the corresponding panel is presented to the user.



 
 
>>> More Python Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: