Welcome, guest | Sign In | My Account | Store | Cart

wxPython provides a powerul functionality that allows you to use a "Notebook" user interface with multiple panels - whose interface each is determined by individual Python scripts. Each panel runs in the background (even when it is not selected), and maintains the state it is in as the user switches back and forth.

Python, 51 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from wxPython.wx import *

class MainFrame(wxFrame):

        .
        .
        .

        def __init__(self, parent, id, title):

                .
                .
                .


                # Create the Notebook

                self.nb = wxNotebook(self, -1, wxPoint(0,0), wxSize(0,0), wxNB_FIXEDWIDTH)

                # Make PANEL_1 (filename: panel1.py)

                self.module = __import__("panel1", globals())
                self.window = self.module.runPanel(self, self.nb)

                if self.window:

                        self.nb.AddPage(self.window, "PANEL_1")


                # Make PANEL_2 (filename: panel2.py)

                self.module = __import__("panel2", globals())
                self.window = self.module.runPanel(self, self.nb)

                if self.window:

                        self.nb.AddPage(self.window, "PANEL_2")


                # Make PANEL_3 (filename: panel3.py)

                self.module = __import__("panel3", globals())
                self.window = self.module.runPanel(self, self.nb)

                if self.window:

                        self.nb.AddPage(self.window, "PANEL_3")

                .
                .
                .

Of course this isn't a fully functional wxPython application, but it demonstrates how to use Notebooks, and panels (which are loaded by means of importing files) adequetly. I assume that the reader has a handle on the basics of wxPython. Of course, this example assumes that you have files named panel1.py, panel2.py, panel3.py which contain a "runPanel" function which basically returns a wxPanel object.

Created by Mark Nenadov on Tue, 19 Jun 2001 (PSF)
Python recipes (4591)
Mark Nenadov's recipes (12)
Python Cookbook Edition 2 (117)
Python Cookbook Edition 1 (103)

Required Modules

  • (none specified)

Other Information and Tasks