【问题标题】:WxPython multiple grid instancesWxPython 多个网格实例
【发布时间】:2011-02-11 23:24:51
【问题描述】:

有人知道如何让同一网格的多个实例显示在一帧上吗?每当我创建超过 1 个相同对象的实例时,原始网格小部件的显示就会完全崩溃,我无法对其进行任何操作。

供参考,代码如下:

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

【问题讨论】:

    标签: wxpython grid


    【解决方案1】:

    您需要将 sizer(vbox) 添加到面板中,因此您应该这样做

    1. 在框架内创建面板
    2. 创建 2 级网格作为面板的子级
    3. 将 levelGrids 添加到 vbox sizer
    4. 将大小调整器添加到面板

    例如

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-24
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      相关资源
      最近更新 更多