例子
以下示例在顶级框架中部署 Notebook 控件。
设计了两个基于 wx.Panel 的类。首先,在其中放置一个多行 TextCtrl。
class MyPanel1(wx.Panel):
def __init__(self, parent):
super(MyPanel1, self).__init__(parent)
text = wx.TextCtrl(self, style = wx.TE_MULTILINE, size = (250,150))
第二个,显示一个具有三个单选按钮的 RadioBox。
class MyPanel2(wx.Panel):
def __init__(self, parent):
super(MyPanel2, self).__init__(parent)
lblList = ['Value X', 'Value Y', 'Value Z']
rbox = wx.RadioBox(self, label = 'RadioBox', pos = (25,10), choices = lblList,
majorDimension = 1, style = wx.RA_SPECIFY_ROWS)
这两个面板类的对象作为页面添加到顶级框架的 Notebook 中。
nb.AddPage(MyPanel1(nb),"Editor")
nb.AddPage(MyPanel2(nb),"RadioButtons")
完整的代码如下 -
import wx
class MyDialog(wx.Dialog):
def __init__(self, parent, title):
super(MyDialog, self).__init__(parent, title = title, size = (250,150))
panel = wx.Panel(self)
self.btn = wx.Button(panel, wx.ID_OK, label = "ok", size = (50,20), pos = (75,50))
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title = title, size = (250,150))
self.InitUI()
def InitUI(self):
nb = wx.Notebook(self)
nb.AddPage(MyPanel1(nb),"Editor")
nb.AddPage(MyPanel2(nb),"RadioButtons")
self.Centre()
self.Show(True)
class MyPanel1(wx.Panel):
def __init__(self, parent):
super(MyPanel1, self).__init__(parent)
text = wx.TextCtrl(self, style = wx.TE_MULTILINE, size = (250,150))
class MyPanel2(wx.Panel):
def __init__(self, parent):
super(MyPanel2, self).__init__(parent)
lblList = ['Value X', 'Value Y', 'Value Z']
rbox = wx.RadioBox(self, label = 'RadioBox', pos = (25,10), choices = lblList,
majorDimension = 1, style = wx.RA_SPECIFY_ROWS)
ex = wx.App()
Mywin(None,'NoteBook demo')
ex.MainLoop()
上面的代码产生以下输出 -