wxPython多个拆分器Windows

时间:2012-07-06 09:04:35

标签: wxpython panels splitter

我正在尝试在一组面板中嵌入分割器窗口,但是当我运行以下操作时,我看到一个闪光灯,好像顶部分割器窗口覆盖了第二个分割器窗口的顶部面板。我试图跟踪框架和面板的孩子,但无法弄清楚顶部的人。任何人都可以帮我解决这个问题并解释为什么布局会发生变化,并且顶部面板会被第二个面板添加到分割器中吗? 谢谢 大卫

#!/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()

1 个答案:

答案 0 :(得分:1)

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

enter image description here

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