wxpython:带有wx.SashLayoutWindow的多个面板
我正在尝试创建这个:
|---------------------------------------------|
| Panel 1a | Panel 2a | Panel 3 |
| | | |
| | | |
|-----------------------------------| |
| Panel 1b | Panel 2b | |
| | | |
|---------------------------------------------|
到目前为止我只能创建这个:
|---------------------------------------------|
| Panel 1a | Panel 2a | Panel 3 |
| | | |
| | | |
|---------------------------------------------|
如何将面板 1a 和面板 2a 分成两半?用分离器?
我的代码如下:
import wx
class TestSashWindow(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
winids = []
leftwin1 = wx.SashLayoutWindow(self, -1, wx.DefaultPosition, (200, 30), wx.NO_BORDER|wx.SW_3D)
leftwin1.SetDefaultSize((120, 1000))
leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
leftwin1.SetAlignment(wx.LAYOUT_RIGHT)
leftwin1.SetSashVisible(wx.SASH_LEFT, True)
self.leftWindow1 = leftwin1
winids.append(leftwin1.GetId())
self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
leftwin2 = wx.SashLayoutWindow(self, -1, wx.DefaultPosition, (200, 30), wx.NO_BORDER|wx.SW_3D)
leftwin2.SetDefaultSize((120, 1000))
leftwin2.SetOrientation(wx.LAYOUT_VERTICAL)
leftwin2.SetAlignment(wx.LAYOUT_LEFT)
leftwin2.SetSashVisible(wx.SASH_RIGHT, True)
self.leftWindow2 = leftwin2
winids.append(leftwin2.GetId())
self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
self.Bind(wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,id=min(winids), id2=max(winids))
self.Bind(wx.EVT_SIZE, self.OnSize)
slw = leftwin1
x = wx.Notebook(slw, -1)
for i in xrange(2):
x.AddPage(wx.Panel(x, -1), str(i))
class mainframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, size=(400,300), title="sash test")
self.a = TestSashWindow(self)
if __name__ == '__main__':
a = wx.App(0)
b = mainframe()
b.Show(1)
a.MainLoop()
Im Trying to create this:
|---------------------------------------------|
| Panel 1a | Panel 2a | Panel 3 |
| | | |
| | | |
|-----------------------------------| |
| Panel 1b | Panel 2b | |
| | | |
|---------------------------------------------|
So far I can only create this:
|---------------------------------------------|
| Panel 1a | Panel 2a | Panel 3 |
| | | |
| | | |
|---------------------------------------------|
How can I split panel 1a and Panel 2a in half? with a splitter?
My code is as follows:
import wx
class TestSashWindow(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
winids = []
leftwin1 = wx.SashLayoutWindow(self, -1, wx.DefaultPosition, (200, 30), wx.NO_BORDER|wx.SW_3D)
leftwin1.SetDefaultSize((120, 1000))
leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
leftwin1.SetAlignment(wx.LAYOUT_RIGHT)
leftwin1.SetSashVisible(wx.SASH_LEFT, True)
self.leftWindow1 = leftwin1
winids.append(leftwin1.GetId())
self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
leftwin2 = wx.SashLayoutWindow(self, -1, wx.DefaultPosition, (200, 30), wx.NO_BORDER|wx.SW_3D)
leftwin2.SetDefaultSize((120, 1000))
leftwin2.SetOrientation(wx.LAYOUT_VERTICAL)
leftwin2.SetAlignment(wx.LAYOUT_LEFT)
leftwin2.SetSashVisible(wx.SASH_RIGHT, True)
self.leftWindow2 = leftwin2
winids.append(leftwin2.GetId())
self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
self.Bind(wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,id=min(winids), id2=max(winids))
self.Bind(wx.EVT_SIZE, self.OnSize)
slw = leftwin1
x = wx.Notebook(slw, -1)
for i in xrange(2):
x.AddPage(wx.Panel(x, -1), str(i))
class mainframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, size=(400,300), title="sash test")
self.a = TestSashWindow(self)
if __name__ == '__main__':
a = wx.App(0)
b = mainframe()
b.Show(1)
a.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
布局管理的一般概念是容器和小部件。在容器中,您可以放置其他容器和小部件。为了完成给定的布局,您必须以巧妙的方式在层次结构中组织容器和小部件。由于您提供的代码仍然不完整,我不会为您提供完整的解决方案,而是回答您的问题如何拆分两个面板。
panel1
、panel2
和panel3
。看来你已经走到这一步了。BoxSizer
)panel1a
和panel1b
,并以panel1
作为父面板。根据需要将小部件放置在这两个面板中。panel2a
和panel2b
,并以panel2
作为父面板。根据需要将小部件放置在这两个面板中。Splitter
(仅当您希望使它们可调整大小时才需要。在这种情况下,panel1
和panel2
> 被分离器取代。有关详细信息,请阅读此示例)可视化:
The generell concept of layout management are containers and widgets. In containers you can place other containers and widgets. To accomplish the given layout, you have to organize your containers and widgets in a hierarchy in a clever way. Since your supplied code is still incomplete, I'll won't provide you with a full solution, but rather answer your question how you can split both panels.
panel1
,panel2
andpanel3
. It seems you've gotten so far.BoxSizer
)panel1a
andpanel1b
withpanel1
as parent. Place widgets in these two panels as wanted.panel2a
andpanel2b
withpanel2
as parent. Place widgets in these two panels as wanted.Splitter
(only if you wish to make them resizable. In that case,panel1
andpanel2
are replaced by splitters. Read this example for details)Visualization: