0

我正在尝试将拆分器窗口嵌入到一组面板中,但是当我运行以下命令时,我看到一个闪光,好像顶部拆分器窗口覆盖了第二个拆分器窗口的顶部面板。我试图跟踪框架和面板的孩子,但无法弄清楚谁在上面。谁能帮我解决这个问题并解释为什么布局发生变化并且顶部面板明显被添加到拆分器的第二个面板掩盖了?谢谢大卫

#!/usr/bin/env python2.6
# encoding: ISO-8859-1
"""
Basic Splitter Panel Skeleton.py
"""

import sys
reload(sys) 
sys.setdefaultencoding("utf-8")
import os
import time
import wx


def timenow():
    return time.time()

########################################################################

class VSplitterPanel(wx.Panel):
    """ Constructs a Vertical splitter window with left and right panels"""
    #----------------------------------------------------------------------
    def __init__(self, parent, color):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour(color)
        splitter = wx.SplitterWindow(self, style = wx.SP_3D| wx.SP_LIVE_UPDATE)
        leftPanel = wx.Panel(splitter)
        rightPanel = wx.Panel(splitter)
        leftPanel.SetBackgroundColour('SEA GREEN')
        rightPanel.SetBackgroundColour('STEEL BLUE')

        splitter.SplitVertically(leftPanel, rightPanel) 
        PanelSizer=wx.BoxSizer(wx.VERTICAL)
        PanelSizer.Add(splitter, 1, wx.EXPAND | wx.ALL)
        self.SetSizer(PanelSizer)
########################################################################

class HSplitterPanel(wx.Panel):
    """ Constructs a Horizontal splitter window with top and bottom panels"""
    #----------------------------------------------------------------------
    def __init__(self, parent, color):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour(color)
        splitter = wx.SplitterWindow(self, style = wx.SP_3D| wx.SP_LIVE_UPDATE)
        TopPanel = wx.Panel(splitter)
        BottomPanel = wx.Panel(splitter)
        TopPanel.SetBackgroundColour('YELLOW GREEN')
        BottomPanel.SetBackgroundColour('SLATE BLUE')


        splitter.SplitHorizontally(TopPanel, BottomPanel) 
        PanelSizer=wx.BoxSizer(wx.VERTICAL)
        PanelSizer.Add(splitter, 1, wx.EXPAND | wx.ALL)
        self.SetSizer(PanelSizer)
########################################################################

class MainFrame(wx.Frame):
    """Constructor"""
    #----------------------------------------------------------------------
    def __init__(self, parent, id):
        wx.Frame.__init__(self, None, title="Basic Splitter Panel Skeleton",size=(800,600))
        t0=timenow()
        self.sb=self.CreateStatusBar()
        ################################################################
        # Define mainsplitter as child of Frame and add H and VSplitterPanel as children
        mainsplitter = wx.SplitterWindow(self, style = wx.SP_3D| wx.SP_LIVE_UPDATE)
        #splitterpanel1 = HSplitterPanel(mainsplitter,'LIGHT BLUE') 
        splitterpanel1 = HSplitterPanel(mainsplitter,'LIGHT BLUE') 
        splitterpanel2 = VSplitterPanel(mainsplitter,'LIGHT BLUE') 
        #print self.GetChildren(),'\n'
        #print splitterpanel1.leftPanel.GetChildren()
        mainsplitter.SplitHorizontally(splitterpanel2, splitterpanel1)
        MainSizer = wx.BoxSizer(wx.VERTICAL)
        MainSizer.Add(mainsplitter, 1, wx.EXPAND | wx.ALL)
        self.SetSizer(MainSizer)
        #################################################################
        self.sb.SetStatusText('Initialized in  %6.4f secs'%(timenow()-t0))
        self.Refresh()
        self.Show()

#---------------------------------------------------------------------- 


if __name__ == '__main__':
    app = wx.App()
    MainFrame(None, -1)
    app.MainLoop()
4

1 回答 1

2

我在 Windows 上运行它时看到以下内容:

在此处输入图像描述

哪个面板搞砸了?无论如何,判断哪个小部件在哪里的最简单方法是使用小部件检查工具。你可以在这里阅读。它易于使用,甚至可以使您的尺寸调整器可见,以帮助您找出布局问题。

于 2012-07-06T14:22:28.203 回答