wxSplitterWindow不显示窗扇

2024-09-20 04:08:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用wxPython构建一个简单的应用程序,我希望使用这样的布局

________
|   |   |
|   |___|
|   |   |
|   |   |
---------

这是我的示例代码

class MainWindow(wx.Frame):
    def __init__(self, title):
        super().__init__(parent=None, title=title)
        self.Maximize()
        self.initUI()

    def initUI(self):
        self.leftSplitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE)
        self.leftSplitter.SetSashInvisible(False)  # not working
        self.rightSplitter = wx.SplitterWindow(self.leftSplitter, style=wx.SP_LIVE_UPDATE)
        self.rightSplitter.SetSashInvisible(False)  # not working

        self.leftPanel = wx.Panel(self.leftSplitter)
        self.rightPanel = wx.Panel(self.rightSplitter)
        self.bottomPanel = wx.Panel(self.rightSplitter)

        self.leftSizer = wx.GridSizer(10, 4, 3, 3)
        self.rightSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.bottomSizer = wx.BoxSizer(wx.HORIZONTAL)

        rightBtn = wx.Button(self.rightPanel, label="I'm on the right")
        leftBtn = wx.Button(self.leftPanel, label="I'm on the left")
        bottomBtn = wx.Button(self.bottomPanel, label="I'm on the bottom")

        self.leftSizer.Add(leftBtn)
        self.rightSizer.Add(rightBtn)
        self.bottomSizer.Add(bottomBtn)

        self.leftPanel.SetSizer(self.leftSizer)
        self.rightPanel.SetSizer(self.rightSizer)
        self.bottomPanel.SetSizer(self.bottomSizer)

        self.rightSplitter.SplitHorizontally(self.rightPanel, self.bottomPanel)
        self.rightSplitter.SetSashGravity(0.5)

        self.leftSplitter.SplitVertically(self.leftPanel, self.rightSplitter)
        self.leftSplitter.SetSashGravity(0.5)


app = wx.App()
frame = MainWindow("My Window")
frame.Show()
app.MainLoop()

当我运行它时,一切都按预期工作,除了窗扇(又名分隔符)在默认情况下不显示之外。 如果我跑的话

self.leftSplitter.IsSashVisible()

我猜错了。如何将窗扇设置为默认可见?如果使用setashinvisible()使其不可见,如何将其设置回可见


Tags: selftitleonbuttonlabelwxpanelleftpanel