请注意:这不是wxPython 的副本:在同一帧中显示多个小部件,这是对问题的额外疑问。
好的,我已经在同一框架上有一个笔记本和一个按钮。源代码:
import wx
import wx.lib.sheet as sheet
class MySheet(sheet.CSheet):
def __init__(self, parent):
sheet.CSheet.__init__(self, parent)
self.SetLabelBackgroundColour('#CCFF66')
self.SetNumberRows(50)
self.SetNumberCols(50)
class Notebook(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(600, 600))
menubar = wx.MenuBar()
file = wx.Menu()
file.Append(101, 'Quit', '' )
menubar.Append(file, "&File")
self.SetMenuBar(menubar)
wx.EVT_MENU(self, 101, self.OnQuit)
nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
self.sheet1 = MySheet(nb)
self.sheet2 = MySheet(nb)
self.sheet3 = MySheet(nb)
nb.AddPage(self.sheet1, "Sheet1")
nb.AddPage(self.sheet2, "Sheet2")
nb.AddPage(self.sheet3, "Sheet3")
self.sheet1.SetFocus()
self.StatusBar()
self.button1 = wx.Button(self, -1, label = "Ok")
#self.button2 = wx.Button(self, -1, label = "Not Ok")
sizerV = wx.BoxSizer(wx.VERTICAL)
# add notebook first, with size factor 2:
sizerV.Add(nb, 5)
# then text, size factor 1, maximized
sizerV.Add(self.button1, 1, wx.EXPAND)
# assign the sizer to Frame:
self.SetSizerAndFit(sizerV)
def StatusBar(self):
self.statusbar = self.CreateStatusBar()
def OnQuit(self, event):
self.Close()
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(450, 400))
self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
self.Center()
class MyApp(wx.App):
def OnInit(self):
frame = Notebook(None, -1, 'Pandel.py')
frame.Show(True)
frame.Center()
frame2 = MyFrame(None, -1, '')
self.SetTopWindow(frame2)
return True
app = MyApp(0)
app.MainLoop()
输出 :
但我想要两个彼此相邻的按钮,而不是屏幕上的一个大按钮。
那就是我想一起使用 wx.HORIZONTAL 和 WX.VERTICAL 尺寸器。我该怎么做呢?