这是我可以做的最简单的例子。它是面板内的网格:
#!/usr/bin/env python
import wx
import wx.grid
app = wx.App(False)
class InfoPane(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent)
# Set up the presentation
self.SetRowLabelSize(0)
self.CreateGrid(1, 6)
self.SetColLabelAlignment( wx.ALIGN_LEFT, wx.ALIGN_CENTRE )
self.SetColLabelValue(0, "Name")
self.SetColLabelValue(1, "Status")
self.SetColLabelValue(2, "")
self.SetColLabelValue(3, "File")
self.SetColLabelValue(4, "Last Action")
self.SetColLabelValue(5, "Other Info")
frame = wx.Frame(None)
panel = wx.Panel(frame)
info_pane = InfoPane(panel)
note_sizer = wx.BoxSizer()
note_sizer.Add(info_pane, 1, wx.EXPAND)
panel.SetSizerAndFit(note_sizer)
frame.Show()
app.MainLoop()
我希望整个事情的大小,以便网格的内容都可见。目前发生的是:
(注意:编辑 - 我拿出了笔记本,为了更简化,结果看起来一样)
想法?谢谢!
答案 0 :(得分:2)
如果在框架上调用fit方法时向框架添加sizer,它将调整其子项的大小。
#!/usr/bin/env python
import wx
import wx.grid
app = wx.App(False)
class InfoPane(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent)
# Set up the presentation
self.SetRowLabelSize(0)
self.CreateGrid(1, 6)
self.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE)
self.SetColLabelValue(0, "Name")
self.SetColLabelValue(1, "Status")
self.SetColLabelValue(2, "")
self.SetColLabelValue(3, "File")
self.SetColLabelValue(4, "Last Action")
self.SetColLabelValue(5, "Other Info")
frame = wx.Frame(None)
panel = wx.Panel(frame)
info_pane = InfoPane(panel)
note_sizer = wx.BoxSizer()
note_sizer.Add(info_pane, 1, wx.EXPAND)
panel.SetSizer(note_sizer)
frame_sizer = wx.BoxSizer(wx.VERTICAL)
frame_sizer.Add(panel, 1, wx.EXPAND)
frame.SetSizerAndFit(frame_sizer)
frame.Show()
app.MainLoop()
答案 1 :(得分:1)
您可以获取网格的大小并使用它调整其父面板的大小。
试试这个:
panel.SetSizerAndFit(note_sizer)
gridSize = info_pane.GetVirtualSize()
frame.Show()
panel.SetSize(gridSize)
frame.Fit()