5 class TestNotebook(wx
.Notebook
): 
   6     def __init__(self
, parent
, ID
=-1): 
   7         wx
.Notebook
.__init
__(self
, parent
, ID
) 
  10         # just a panel with a small fixed size 
  11         p 
= wx
.Panel(self
, size
=(50,50)) 
  12         self
.AddPage(p
, "page 1") 
  15         # a medium sized panel with manually layed out controls 
  17         b 
= wx
.Button(p
, -1, "a button", (20,20)) 
  18         b 
= wx
.Button(p
, -1, "another button", (80,80)) 
  19         b 
= wx
.Button(p
, -1, "and yet another button", (140,140)) 
  20         b
.Bind(wx
.EVT_BUTTON
, self
.ShowBestSizes
) 
  21         self
.AddPage(p
, "page 2") 
  24         # a larger panel with lots of controls in a sizer. 
  25         text 
= "one two buckle my shoe three four shut the door "\
 
  26                "five six pick up sticks seven eight lay them straight "\
 
  27                "nine ten big fat hen" 
  29         fgs 
= wx
.FlexGridSizer(cols
=4, vgap
=5, hgap
=5) 
  30         for word 
in text
.split(): 
  31             label 
= wx
.StaticText(p
, -1, word
+":") 
  32             tc 
= wx
.TextCtrl(p
, -1, "", size
=(120,-1)) 
  33             fgs
.Add(label
, flag
=wx
.ALIGN_RIGHT | wx
.ALIGN_CENTER_VERTICAL | wx
.LEFT
, border
=10) 
  34             fgs
.Add(tc
, flag
=wx
.RIGHT
, border
=10) 
  36         box
.Add(fgs
, 1, wx
.EXPAND|wx
.ALL
, 10) 
  38         self
.AddPage(p
, "page 3") 
  41     # show the best size of each page 
  42     def ShowBestSizes(self
, evt
): 
  43         for num 
in range(self
.GetPageCount()): 
  44             page 
= self
.GetPage(num
) 
  45             print page
.GetBestSize() 
  48 if __name__ 
== '__main__': 
  49     app 
= wx
.PySimpleApp() 
  50     f 
= wx
.Frame(None, -1, "Notebook Test") 
  53     s
.Add(nb
)           # notebook is added directly to the sizer 
  55     s
.Fit(f
)            # sizer calculates layout to set frame size