我正在尝试使用窗口分割器来获得6个不同的子窗口。三列两行。到目前为止,我正在尝试使用嵌套分割器,但它无法正常工作。
这是我的代码:
import wx
########################################################################
class RandomPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent, color):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(color)
########################################################################
class MainPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
topSplitter = wx.SplitterWindow(self)
vSplitter = wx.SplitterWindow(topSplitter)
panelOne = RandomPanel(vSplitter, "blue")
panelTwo = RandomPanel(vSplitter, "red")
vSplitter.SplitVertically(panelOne, panelTwo)
vSplitter.SetSashGravity(0.5)
panelThree = RandomPanel(topSplitter, "green")
topSplitter.SplitHorizontally(vSplitter, panelThree)
topSplitter.SetSashGravity(0.5)
panelFour=RandomPanel(hSplitter, "yellow")
hSplitter.SplitVertically(topSplitter, panelFour)
hSplitter.SetSashGravity(0.5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(topSplitter, 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)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
为此,我只是想让4个子窗口不是6,我仍然会收到错误。
答案 0 :(得分:0)
您可能想要查看MultiSplitterWindow
小部件:
它允许您在拆分器窗口小部件中拥有两个以上的窗口。我实际上写了一些关于wxPython在blog上支持的各种分割窗口,所以你可能也想检查一下。
无论如何,这是一个使用该小部件的简单示例:
import wx
from wx.lib.splitter import MultiSplitterWindow
class SplitterPanel(wx.Panel):
def __init__(self, parent, color):
"""Constructor"""
wx.Panel.__init__(self, parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE)
for col in range(3):
panel = wx.Panel(splitter, size=(200, 200))
panel.SetBackgroundColour(color)
splitter.AppendWindow(panel)
main_sizer.Add(splitter, 1, wx.ALL|wx.EXPAND)
self.SetSizer(main_sizer)
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='Splitters')
panel = wx.Panel(self)
main_sizer = wx.BoxSizer(wx.VERTICAL)
splitter_panel = SplitterPanel(panel, color='blue')
main_sizer.Add(splitter_panel, 1, wx.ALL|wx.EXPAND)
splitter_panel_two = SplitterPanel(panel, color='red')
main_sizer.Add(splitter_panel_two, 1, wx.ALL|wx.EXPAND)
panel.SetSizer(main_sizer)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MainFrame()
app.MainLoop()