wxPython电子表格功能电子表格功能wx.grid实例教程实例教程
主要介绍了wxPython电子表格功能wx.grid实例教程,文中示例代码介绍的非常详细,具有一定的参考价值,感
兴趣的小伙伴们可以参考一下
本文实例为大家分享了wxPython电子表格功能的具体代码,供大家参考,具体内容如下
#!/usr/bin/env python
#encoding: utf8
import wx
import wx.grid as gridlib
#import wx.lib.mixins.grid as mixins
#---------------------------------------------------------------------------
class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
##mixins.GridAutoEditMixin.__init__(self)
#打印log信息
self.log = log
self.moveTo = None
self.Bind(wx.EVT_IDLE, self.OnIdle)
#创建一个25X25的电子表格
self.CreateGrid(25, 25)#, gridlib.Grid.SelectRows)
##self.EnableEditing(False)
#simple cell formatting
#设置第index=3列的宽度大小,像素=200
self.SetColSize(col=3,width=200)
#设置第index=4行的高度大小,像素=45
self.SetRowSize(4, 45)
#设置 row=0,col=0,value="First cell"
self.SetCellValue(0, 0, "First cell")
#设置 row=1,col=1,value="Another cell"
self.SetCellValue(1, 1, "Another cell")
#设置 row=2,col=2,value="Yet another cell"
self.SetCellValue(2, 2, "Yet another cell")
#设置 row=3,col=3,value="This cell is read-only"
self.SetCellValue(3, 3, "This cell is read-only")
#设置字体格式
self.SetCellFont(0, 0, wx.Font(12, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
#设置字体颜色
self.SetCellTextColour(1, 1, wx.RED)
#设置cell背景颜色
self.SetCellBackgroundColour(2, 2, wx.CYAN)
#设置只读属性
self.SetReadOnly(3, 3, True)
#设置 row=5,col=0,数字编辑器
self.SetCellEditor(5, 0, gridlib.GridCellNumberEditor(1,1000))
#设置 row=5,col=0,value="123"
self.SetCellValue(5, 0, "123")
#设置 row=6,col=0,浮点数
self.SetCellEditor(6, 0, gridlib.GridCellFloatEditor())
#设置 row=6,col=0,value="123.34"
self.SetCellValue(6, 0, "123.34")
#设置
self.SetCellEditor(7, 0, gridlib.GridCellNumberEditor())
#设置 row=6,col=3,value="You can veto editing this cell"
self.SetCellValue(6, 3, "You can veto editing this cell")
#self.SetRowLabelSize(0)
#self.SetColLabelSize(0)
# attribute objects let you keep a set of formatting values
# in one spot, and reuse them if needed
#wx.grid.GridCellAttr
#这个类可以用来通过改变它们的默认属性来改变网格在网格中的外观。
attr = gridlib.GridCellAttr()
#字体颜色:黑色
attr.SetTextColour(wx.BLACK)
#设置背景颜色:红色
attr.SetBackgroundColour(wx.RED)
#设置字体格式
attr.SetFont(wx.Font(10, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
# you can set cell attributes for the whole row (or column)
评论0
最新资源