Use a notebook control (Phoenix)

Keywords : Notebook, Frame, Panel, Page, Tab.


Introduction :

A simple example of using a wx.Notebook to implement a tabbed interface with 3 page windows.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


First example

img_sample_one.png

   1 # sample_one.py
   2 
   3 import wx
   4 
   5 # class MyPageOne
   6 # class MyPageTwo
   7 # class MyPageThree
   8 # class MyFrame
   9 # class MyApp
  10 
  11 #---------------------------------------------------------------------------
  12 
  13 class MyPageOne(wx.Panel):
  14     def __init__(self, parent):
  15         wx.Panel.__init__(self, parent)
  16 
  17         #------------
  18 
  19         self.SetBackgroundColour(wx.Colour("Green"))
  20 
  21         #------------
  22 
  23         txt = wx.StaticText(self, -1,
  24                             """This is a "MyPageOne" object""",
  25                             (20, 20))
  26 
  27 #---------------------------------------------------------------------------
  28 
  29 class MyPageTwo(wx.Panel):
  30     def __init__(self, parent):
  31         wx.Panel.__init__(self, parent)
  32 
  33         #------------
  34 
  35         self.SetBackgroundColour(wx.Colour("Yellow"))
  36 
  37         #------------
  38 
  39         txt = wx.StaticText(self, -1,
  40                             """This is a "MyPageTwo" object""",
  41                             (40, 40))
  42 
  43 #---------------------------------------------------------------------------
  44 
  45 class MyPageThree(wx.Panel):
  46     def __init__(self, parent):
  47         wx.Panel.__init__(self, parent)
  48 
  49         #------------
  50 
  51         self.SetBackgroundColour(wx.Colour("Light Gray"))
  52 
  53         #------------
  54 
  55         txt = wx.StaticText(self, -1,
  56                             """This is a "MyPageThree" object""",
  57                             (60, 60))
  58 
  59 #---------------------------------------------------------------------------
  60 
  61 class MyFrame(wx.Frame):
  62     def __init__(self, parent, id, title):
  63         wx.Frame.__init__(self, parent, id, title)
  64 
  65         self.SetIcon(wx.Icon("wxwin.ico"))
  66 
  67         #------------
  68 
  69         # Here we create a panel and a notebook on the panel.
  70         pnl = wx.Panel(self)
  71         nb = wx.Notebook(pnl)
  72 
  73         #------------
  74 
  75         # Ccreate the page windows as children of the notebook.
  76         page1 = MyPageOne(nb)
  77         page2 = MyPageTwo(nb)
  78         page3 = MyPageThree(nb)
  79 
  80         #------------
  81 
  82         # Add the pages to the notebook with the label to show on the tab.
  83         nb.AddPage(page1, "Page 1")
  84         nb.AddPage(page2, "Page 2")
  85         nb.AddPage(page3, "Page 3")
  86 
  87         #------------
  88 
  89         # Finally, put the notebook in a sizer for
  90         # the panel to manage the layout.
  91         sizer = wx.BoxSizer()
  92         sizer.Add(nb, 1, wx.EXPAND)
  93         pnl.SetSizer(sizer)
  94 
  95 #---------------------------------------------------------------------------
  96 
  97 class MyApp(wx.App):
  98     def OnInit(self):
  99 
 100         #------------
 101 
 102         frame = MyFrame(None, -1,
 103                         "Simple notebook example")
 104         self.SetTopWindow(frame)
 105         frame.Show(True)
 106 
 107         return True
 108 
 109 #---------------------------------------------------------------------------
 110 
 111 def main():
 112     app = MyApp(redirect=False)
 113     app.MainLoop()
 114 
 115 #---------------------------------------------------------------------------
 116 
 117 if __name__ == "__main__" :
 118     main()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

??? (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

12/01/20 - Ecco (Updated page for wxPython Phoenix).


Comments

- blah, blah, blah....

Use a notebook control (Phoenix) (last edited 2020-10-07 10:26:34 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.