嵌套面板的 Wxpython 大小及其在调整整个应用程序大小时的行为
Wxpython size of nested panel and it's behavior when resizing whole application
我的问题是关于 "panelThree" 在代码中的行为。我给它上色,这表明我的面板中的 space 非常小。我真的不知道我在哪里犯了错误。关于 panelThree 行为的第二件事是,当您最大化整个应用程序并返回到默认大小时,它会变得很奇怪,可能是因为它没有背景,但它与以前的连接。
代码如下:
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()
我认为你的问题是你没有在里面放任何东西。
尝试将 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)
这加入了text_ctrl里面有一些数据,看看区别!
如果您打算使用 AuiNoteBook,您可能应该阅读或重新阅读这篇文章 http://www.wiki.wxpython.org/AuiNotebook%20%28AGW%29
虽然 wx.Aui 将自己标记为前沿,但可能存在问题,因为它不会像更普通的标准版本那样经过广泛测试,在这种情况下 wx.NoteBook.
我的问题是关于 "panelThree" 在代码中的行为。我给它上色,这表明我的面板中的 space 非常小。我真的不知道我在哪里犯了错误。关于 panelThree 行为的第二件事是,当您最大化整个应用程序并返回到默认大小时,它会变得很奇怪,可能是因为它没有背景,但它与以前的连接。
代码如下:
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()
我认为你的问题是你没有在里面放任何东西。
尝试将 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)
这加入了text_ctrl里面有一些数据,看看区别!
如果您打算使用 AuiNoteBook,您可能应该阅读或重新阅读这篇文章 http://www.wiki.wxpython.org/AuiNotebook%20%28AGW%29
虽然 wx.Aui 将自己标记为前沿,但可能存在问题,因为它不会像更普通的标准版本那样经过广泛测试,在这种情况下 wx.NoteBook.