wx.SplitterWindow 的 sizer 不工作 wxPython
Sizers for wx.SplitterWindow not working wxPython
所以我有三个拆分器 windows,我正在尝试使用 sizer,以便它们在调整大小时等时表现正常。这是我现在拥有的代码。它不起作用。
class SplitterFrame (wx.Frame):
def __init__(self):
#Create a master window
self.mainframe = wx.Frame.__init__(self,None,title = 'some frame')
self.splitter = wx.SplitterWindow(self,-1, style = wx.SP_LIVE_UPDATE)
self.splitter2 = wx.SplitterWindow(self.splitter,-1, style = wx.SP_LIVE_UPDATE)
self.splitter.SetMinimumPaneSize(330)
self.splitter2.SetMinimumPaneSize(160)
self.panel1 = wx.Panel(self.splitter,-1)
self.panel1.SetBackgroundColour(wx.WHITE)
self.panel2 = wx.Panel(self.splitter2,-1)
self.panel2.SetBackgroundColour(wx.WHITE)
self.panel3 = wx.Panel(self.splitter2, -1)
self.panel3.SetBackgroundColour(wx.WHITE)
#Splitter window attributes
self.splitter2.SplitVertically(self.panel2,self.panel3, 100)
self.splitter.SplitVertically(self.panel1,self.splitter2, 200)
self.splitter.SetSashGravity(0)
self.splitter2.SetSashGravity(1)
self.splitter.SetSashPosition(1,redraw = True)
self.splitter2.SetSashPosition(10000,redraw = True)
self.Centre()
self.Layout()
self.Maximize(True)
self.Bind(wx.EVT_CLOSE,self.OnClose)
#Set Sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.splitter,1,wx.ALL|wx.EXPAND)
sizer.Add(self.splitter2,1,wx.ALL|wx.EXPAND)
self.SetSizer(sizer)
有人可以告诉我如何对此应用正确的 sizer 吗?我对 sizer 一点都不擅长,所以我只是使用上面的那些,因为我在这里找到它们 [wxPython Splitter windows and Panels .
您不能将两个拆分器都添加到 sizer 中,因为它们在 windows 的层次结构中不是兄弟姐妹。所以你有一个分离器,然后是其中一个面板中的另一个分离器。 sizer不会帮助你,因为sizer直接用sizer里面的windows,但是你的sizer里面只有一个window(self.splitter),另一个(self.splitter 2) 里面是self.splitter。因此,尺寸调整必须在分离器内部进行。您将必须处理框架的 OnSize 事件,并在那里调整内部拆分器的大小。
编辑:添加了代码。
class SplitterFrame (wx.Frame):
def __init__(self):
#Create a master window
wx.Frame.__init__(self,None,title = 'some frame')
self.splitter = wx.SplitterWindow(self,-1, style = wx.SP_LIVE_UPDATE)
self.splitter2 = wx.SplitterWindow(self.splitter,-1, style = wx.SP_LIVE_UPDATE)
self.splitter.SetMinimumPaneSize(20)
self.splitter2.SetMinimumPaneSize(20)
self.panel1 = wx.Panel(self.splitter,-1)
self.panel1.SetBackgroundColour(wx.WHITE)
self.panel2 = wx.Panel(self.splitter2,-1)
self.panel2.SetBackgroundColour(wx.WHITE)
self.panel3 = wx.Panel(self.splitter2, -1)
self.panel3.SetBackgroundColour(wx.WHITE)
#Splitter window attributes
self.splitter2.SplitVertically(self.panel2,self.panel3, 100)
self.splitter.SplitVertically(self.panel1,self.splitter2, 100)
self.splitter.SetSashGravity(0)
self.splitter2.SetSashGravity(1)
self.Centre()
self.Layout()
self.Maximize(True)
self.Bind(wx.EVT_SIZE, self.OnSize)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.splitter,2,wx.ALL|wx.EXPAND)
self.SetSizer(sizer)
def OnSize(self, evt):
evt.Skip()
# here you will change the sash positions to your liking
self.splitter.SetSashPosition(100,redraw = True)
self.splitter2.SetSashPosition(200,redraw = True)
所以我有三个拆分器 windows,我正在尝试使用 sizer,以便它们在调整大小时等时表现正常。这是我现在拥有的代码。它不起作用。
class SplitterFrame (wx.Frame):
def __init__(self):
#Create a master window
self.mainframe = wx.Frame.__init__(self,None,title = 'some frame')
self.splitter = wx.SplitterWindow(self,-1, style = wx.SP_LIVE_UPDATE)
self.splitter2 = wx.SplitterWindow(self.splitter,-1, style = wx.SP_LIVE_UPDATE)
self.splitter.SetMinimumPaneSize(330)
self.splitter2.SetMinimumPaneSize(160)
self.panel1 = wx.Panel(self.splitter,-1)
self.panel1.SetBackgroundColour(wx.WHITE)
self.panel2 = wx.Panel(self.splitter2,-1)
self.panel2.SetBackgroundColour(wx.WHITE)
self.panel3 = wx.Panel(self.splitter2, -1)
self.panel3.SetBackgroundColour(wx.WHITE)
#Splitter window attributes
self.splitter2.SplitVertically(self.panel2,self.panel3, 100)
self.splitter.SplitVertically(self.panel1,self.splitter2, 200)
self.splitter.SetSashGravity(0)
self.splitter2.SetSashGravity(1)
self.splitter.SetSashPosition(1,redraw = True)
self.splitter2.SetSashPosition(10000,redraw = True)
self.Centre()
self.Layout()
self.Maximize(True)
self.Bind(wx.EVT_CLOSE,self.OnClose)
#Set Sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.splitter,1,wx.ALL|wx.EXPAND)
sizer.Add(self.splitter2,1,wx.ALL|wx.EXPAND)
self.SetSizer(sizer)
有人可以告诉我如何对此应用正确的 sizer 吗?我对 sizer 一点都不擅长,所以我只是使用上面的那些,因为我在这里找到它们 [wxPython Splitter windows and Panels .
您不能将两个拆分器都添加到 sizer 中,因为它们在 windows 的层次结构中不是兄弟姐妹。所以你有一个分离器,然后是其中一个面板中的另一个分离器。 sizer不会帮助你,因为sizer直接用sizer里面的windows,但是你的sizer里面只有一个window(self.splitter),另一个(self.splitter 2) 里面是self.splitter。因此,尺寸调整必须在分离器内部进行。您将必须处理框架的 OnSize 事件,并在那里调整内部拆分器的大小。
编辑:添加了代码。
class SplitterFrame (wx.Frame):
def __init__(self):
#Create a master window
wx.Frame.__init__(self,None,title = 'some frame')
self.splitter = wx.SplitterWindow(self,-1, style = wx.SP_LIVE_UPDATE)
self.splitter2 = wx.SplitterWindow(self.splitter,-1, style = wx.SP_LIVE_UPDATE)
self.splitter.SetMinimumPaneSize(20)
self.splitter2.SetMinimumPaneSize(20)
self.panel1 = wx.Panel(self.splitter,-1)
self.panel1.SetBackgroundColour(wx.WHITE)
self.panel2 = wx.Panel(self.splitter2,-1)
self.panel2.SetBackgroundColour(wx.WHITE)
self.panel3 = wx.Panel(self.splitter2, -1)
self.panel3.SetBackgroundColour(wx.WHITE)
#Splitter window attributes
self.splitter2.SplitVertically(self.panel2,self.panel3, 100)
self.splitter.SplitVertically(self.panel1,self.splitter2, 100)
self.splitter.SetSashGravity(0)
self.splitter2.SetSashGravity(1)
self.Centre()
self.Layout()
self.Maximize(True)
self.Bind(wx.EVT_SIZE, self.OnSize)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.splitter,2,wx.ALL|wx.EXPAND)
self.SetSizer(sizer)
def OnSize(self, evt):
evt.Skip()
# here you will change the sash positions to your liking
self.splitter.SetSashPosition(100,redraw = True)
self.splitter2.SetSashPosition(200,redraw = True)