开发者

WxPython multiple grid instances

Does anybody know how I can get multiple instances of the same grid to display on one frame? Whenever I create more than 1 instance of the same object, the display of the original grid widget completely collapses and I'm left unable to do anything with it.

For reference, here's the code:

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()


You will need to add sizer(vbox) to a panel, so you should be doing this

  1. Create a panel inside frame
  2. Create 2 level Grids as child of panel
  3. Add levelGrids to vbox sizer
  4. Add sizer to panel

e.g.

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜