我的问题是关于代码中“panelThree”的行为。我给它着色了,这表明我的面板中的空间非常小。我真的不知道我哪弄错了。关于panelThree行为的第二件事是,当你最大化整个应用程序并恢复到默认大小时,它变得很奇怪,可能是因为它没有背景,但是它与之前的连接。
以下是代码:
import wx
import wx.aui
import wx.grid as gridlib
########################################################################
class ColorPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.SetBackgroundColour((193,255,193))
class MenuPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
notebook = wx.aui.AuiNotebook(self)
page = wx.SplitterWindow(notebook)
menuSplitter = wx.SplitterWindow(page)
Color = ColorPanel(page)
Color.SetBackgroundColour((193,255,193))
notebook.AddPage(page, "Colors Menu")
#notebook.AddPage(page, "Colors Menu2")
#notebook.AddPage(page, "Colors Menu2")
#notebook.AddPage(page, "Colors Menu2")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.EXPAND)
self.SetSizer(sizer)
########################################################################
class GridPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.grid = gridlib.Grid(self, style=wx.BORDER_SUNKEN)
self.grid.CreateGrid(25,25)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.grid, 1, wx.EXPAND)
self.SetSizer(sizer)
def Create (self,Rows,Cols):
self.grid.CreateGrid(Rows,Cols)
#def Fill (self,ValuesList)
#def Colour (self, ColorList) #Color list format [(Color,Value1,Value2=None)]
########################################################################
class MainPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
notebook = wx.aui.AuiNotebook(self)
page = wx.SplitterWindow(notebook)
notebook.AddPage(page, "Splitter")
hSplitter = wx.SplitterWindow(page)
panelOne = GridPanel(hSplitter)
panelTwo = GridPanel(hSplitter)
panelThree = MenuPanel(page)
hSplitter.SplitHorizontally(panelOne, panelTwo)
page.SplitVertically(hSplitter, panelThree)
hSplitter.SetSashGravity(0.5)
page.SetSashGravity(0.70)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.EXPAND)
self.SetSizer(sizer)
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Nested Splitters",
size=(800,600))
panel = MainPanel(self)
menubar = wx.MenuBar()
fileMenu = wx.Menu()
fileMenu.Append(wx.ID_NEW, '&New\tCtrl+N')
fileMenu.Append(wx.ID_OPEN, '&Open\tCtrl+O')
fileMenu.Append(wx.ID_SAVE, '&Save\tCtrl+S')
fileMenu.AppendSeparator()
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
答案 0 :(得分:0)
我相信你的问题是你没有把任何东西放在里面
尝试将class MenuPanel
更改为:
class MenuPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
notebook = wx.Notebook(self)
page = wx.SplitterWindow(notebook)
text_ctrl = wx.TextCtrl(notebook, style=wx.TE_MULTILINE)
text_ctrl.SetValue("A whole bunch of text\nand then some more\nand finally some more")
menuSplitter = wx.SplitterWindow(page)
Color = ColorPanel(page)
Color.SetBackgroundColour((193,255,193))
notebook.AddPage(text_ctrl, "Colors Menu")
#notebook.AddPage(page, "Colors Menu2")
#notebook.AddPage(page, "Colors Menu2")
#notebook.AddPage(page, "Colors Menu2")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.EXPAND)
self.SetSizer(sizer)
这增加了text_ctrl,它有一些数据并看到差异!
如果您打算使用AuiNoteBook,您应该阅读或重新阅读http://www.wiki.wxpython.org/AuiNotebook%20%28AGW%29
虽然wx.Aui将自己标记为最前沿,但可能存在问题,因为它不会像更普通的标准版本那样进行广泛测试,在本例中为wx.NoteBook。