简体   繁体   English

Wxpython嵌套面板的大小及其在调整整个应用程序大小时的行为

[英]Wxpython size of nested panel and it's behavior when resizing whole application

My problem is about behavior of "panelThree" in code. 我的问题是代码中“ panelThree”的行为。 I coloured it and that showed me that space in my panel is really tiny. 我给它上色,这表明我面板上的空间很小。 I don't really know where i made mistake. 我真的不知道我在哪里犯错。 The second thing about panelThree behavior is that when you maximalize whole app and back to default size, it's getting wierd, maybe because it don't have background, but it's connect with previous. 关于panelThree行为的第二件事是,当您最大化整个应用程序并恢复为默认大小时,它变得越来越奇怪,这可能是因为它没有背景,但是与以前的背景有关。

Here's the code: 这是代码:

import wx
import wx.aui
import wx.grid as gridlib

########################################################################
class ColorPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour((193,255,193))




class MenuPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        notebook = wx.aui.AuiNotebook(self)
        page = wx.SplitterWindow(notebook)
        menuSplitter = wx.SplitterWindow(page)

        Color = ColorPanel(page)
        Color.SetBackgroundColour((193,255,193))

        notebook.AddPage(page, "Colors Menu")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        self.SetSizer(sizer)


########################################################################
class GridPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.grid = gridlib.Grid(self, style=wx.BORDER_SUNKEN)
        self.grid.CreateGrid(25,25)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.grid, 1, wx.EXPAND)
        self.SetSizer(sizer)
    def Create (self,Rows,Cols):
        self.grid.CreateGrid(Rows,Cols)
    #def Fill (self,ValuesList)

    #def Colour (self, ColorList) #Color list format [(Color,Value1,Value2=None)]
########################################################################
class MainPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        notebook = wx.aui.AuiNotebook(self)

        page = wx.SplitterWindow(notebook)
        notebook.AddPage(page, "Splitter")
        hSplitter = wx.SplitterWindow(page)

        panelOne = GridPanel(hSplitter)
        panelTwo = GridPanel(hSplitter)
        panelThree = MenuPanel(page)
        hSplitter.SplitHorizontally(panelOne, panelTwo)
        page.SplitVertically(hSplitter, panelThree)
        hSplitter.SetSashGravity(0.5)
        page.SetSashGravity(0.70)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        self.SetSizer(sizer)


########################################################################
class MainFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Nested Splitters",
                          size=(800,600))
        panel = MainPanel(self)

        menubar = wx.MenuBar()

        fileMenu = wx.Menu()
        fileMenu.Append(wx.ID_NEW, '&New\tCtrl+N')
        fileMenu.Append(wx.ID_OPEN, '&Open\tCtrl+O')
        fileMenu.Append(wx.ID_SAVE, '&Save\tCtrl+S')
        fileMenu.AppendSeparator()

        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)
        self.Show()

#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    frame = MainFrame()
    app.MainLoop()

I believe that your issue is that you haven't put anything in it. 我相信您的问题是您没有放任何东西。
Try changing class MenuPanel to this: 尝试将class MenuPanel更改为此:

class MenuPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        notebook = wx.Notebook(self)
        page = wx.SplitterWindow(notebook)
        text_ctrl = wx.TextCtrl(notebook, style=wx.TE_MULTILINE)
        text_ctrl.SetValue("A whole bunch of text\nand then some more\nand finally some more")
        menuSplitter = wx.SplitterWindow(page)

        Color = ColorPanel(page)
        Color.SetBackgroundColour((193,255,193))

        notebook.AddPage(text_ctrl, "Colors Menu")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        self.SetSizer(sizer)

This adds in text_ctrl which has some data and see the difference! 这会在text_ctrl中添加一些数据,看看有什么区别!
If you are going to use AuiNoteBook you should probably read or re-read this http://www.wiki.wxpython.org/AuiNotebook%20%28AGW%29 如果要使用AuiNoteBook,则可能应该阅读或重新阅读此http://www.wiki.wxpython.org/AuiNotebook%20%28AGW%29
Whilst wx.Aui labels itself as cutting edge, there can be issues, as it will not have been as extensively tested as the more mundane standard version, in this case wx.NoteBook. 尽管wx.Aui将自身标记为最先进,但是可能会出现问题,因为它没有像更普通的标准版本(在本例中为wx.NoteBook)那样经过广泛的测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM