Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an entire row/column as read only in wx.grid (wxpython)?

Following code sets a cell readonly, but how to set an entire row/column (for example 3rd column) as read only in wx.grid?

import wx.grid as gridlib

myGrid = gridlib.Grid(panel)
myGrid.SetReadOnly(3, 3, True)
like image 323
alwbtc Avatar asked Mar 22 '23 11:03

alwbtc


1 Answers

You have to use GridCellAttr to do this. Here's a simple example:

import wx
import wx.grid as gridlib

########################################################################
class MyForm(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, parent=None, title="A Simple Grid")
        panel = wx.Panel(self)

        myGrid = gridlib.Grid(panel)
        myGrid.CreateGrid(12, 8)

        # get the cell attribute for the top left row
        editor = myGrid.GetCellEditor(0,0)
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        myGrid.SetRowAttr(0, attr)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(myGrid, 1, wx.EXPAND)
        panel.SetSizer(sizer)

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

This code will make the first row read-only.

like image 188
Mike Driscoll Avatar answered Mar 25 '23 20:03

Mike Driscoll