2010-04-24 77 views
0

是否有人知道如何讓同一個網格的多個實例顯示在一個框架上?每當我創建同一個對象的多個實例時,原始網格控件的顯示完全崩潰,我無法對它做任何事情。WxPython多個網格實例

僅供參考,下面的代碼:

import wx 
import wx.grid as gridlib 

class levelGrid(gridlib.Grid): 
    def __init__(self, parent, rows, columns): 
     gridlib.Grid.__init__(self, parent, -1) 
     self.moveTo = None 
     self.CreateGrid(rows, columns) 

     self.SetDefaultColSize(32) 
     self.SetDefaultRowSize(32) 
     self.SetColLabelSize(0) 
     self.SetRowLabelSize(0) 
     self.SetDefaultCellBackgroundColour(wx.BLACK) 
     self.EnableDragGridSize(False) 


class mainFrame(wx.Frame): 
    def __init__(self, parent, id, title): 
     wx.Frame.__init__(self, parent, id, title, size=(768, 576)) 
     editor = levelGrid(self, 25, 25) 
     panel1 = wx.Panel(editor, -1) 

     #vbox = wx.BoxSizer(wx.VERTICAL) 
     #vbox.Add(editor, 1, wx.EXPAND | wx.ALL, 5) 

     #selector = levelGrid(self, 1, 25) 
     #vbox.Add(selector, 1, wx.EXPAND |wx.BOTTOM, 5) 

     self.Centre() 
     self.Show(True) 

app = wx.App() 
mainFrame(None, -1, "SLAE") 
app.MainLoop() 

回答

1

您需要分級機(VBOX)添加到面板,所以你應該做這個

  1. 創建內部框架
  2. 面板
  3. 創建2級柵格作爲面板的子項
  4. 將levelGrid添加到vbox sizer
  5. 將面板添加到面板

例如

class mainFrame(wx.Frame): 
    def __init__(self, parent, id, title): 
     wx.Frame.__init__(self, parent, id, title, size=(768, 576)) 

     panel = wx.Panel(self, -1) 

     editor = levelGrid(panel, 15, 25) 
     selector = levelGrid(panel, 1, 25) 
     selector.SetDefaultCellBackgroundColour(wx.BLUE) 
     vbox = wx.BoxSizer(wx.VERTICAL) 
     vbox.Add(editor, 0, wx.EXPAND | wx.ALL, 5) 
     vbox.Add(selector, 1, wx.EXPAND |wx.BOTTOM, 5) 
     panel.SetSizerAndFit(vbox) 

     self.Centre() 
     self.Show(True)