wxpython:带有wx.SashLayoutWindow的多个面板

发布于 2024-12-25 21:03:54 字数 2375 浏览 0 评论 0原文

我正在尝试创建这个:

|---------------------------------------------|
| 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜警司 2025-01-01 21:03:54

布局管理的一般概念是容器和小部件。在容器中,您可以放置​​其他容器和小部件。为了完成给定的布局,您必须以巧妙的方式在层次结构中组织容器和小部件。由于您提供的代码仍然不完整,我不会为您提供完整的解决方案,而是回答您的问题如何拆分两个面板。

  1. 创建两个面板,即 panel1panel2panel3。看来你已经走到这一步了。
  2. 在两者上设置大小调整器(例如 BoxSizer
  3. 创建两个面板,panel1apanel1b,并以 panel1 作为父面板。根据需要将小部件放置在这两个面板中。
  4. 创建两个面板:panel2apanel2b,并以 panel2 作为父面板。根据需要将小部件放置在这两个面板中。
  5. 完毕!对于所需的布局,您不一定需要 Splitter(仅当您希望使它们可调整大小时才需要。在这种情况下,panel1panel2 > 被分离器取代。有关详细信息,请阅读此示例

可视化:

+ mainframe (horizontal layout)
|
+-panel1 (vertical layout)
| +-panel1a
| +-panel1b
|
+-panel2 (vertical layout)
| +panel2a
| +panel2b
|
+-panel3

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.

  1. Create two panels, namely panel1, panel2 and panel3. It seems you've gotten so far.
  2. Set sizers on both (for instance a BoxSizer)
  3. Create two panels, panel1a and panel1b with panel1 as parent. Place widgets in these two panels as wanted.
  4. Create two panels, panel2a and panel2b with panel2 as parent. Place widgets in these two panels as wanted.
  5. Done! For the desired layout, you don't necessarily need a Splitter (only if you wish to make them resizable. In that case, panel1 and panel2 are replaced by splitters. Read this example for details)

Visualization:

+ mainframe (horizontal layout)
|
+-panel1 (vertical layout)
| +-panel1a
| +-panel1b
|
+-panel2 (vertical layout)
| +panel2a
| +panel2b
|
+-panel3
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文