wxpython 表格粘贴,wxpython Phoenix grid 电子表格使用过程 and python3.4

wxpython使用grid做电子表格显示数据的时候再网上有很多的例子。但是很多是测试不能通过,总是报错。自己亲自做了一个并且通过测试。高手飘过,如有错误请联系。我运行的环境是python3.4版本,wxpython Phoenix最新的版本。上代码。

先把下面的这个代码保存为

sizers_data_001.py

#-*- encoding:UTF-8 -*-

import wx

import wx.grid

import time

class StudentInfoGridTable(wx.grid.GridTableBase):

def __init__(self):

wx.grid.GridTableBase.__init__(self)

#self.datas = datas

for i in range(3):

i=i+1

#time.sleep( 1 )

print (i)

daii=str(i)

self.data = { (1,1) : "Here",

(1,2) : "is",

(3,3) : "some",

(4,4) : "data",

(1,2) : "Here",

(2,3) : "is",

(4,3) : "some",

(3,4) : daii,

}

self.odd = wx.grid.GridCellAttr()

self.odd.SetReadOnly(True)

self.odd.SetBackgroundColour('yellow')

self.even = wx.grid.GridCellAttr()

self.even.SetReadOnly(True)

pass

def GetNumberRows(self):

return 10

#return len(self.datas)

def GetNumberCols(self):

return 6

#return len(self.colLabels)

def IsEmptyCell(self, row, col):

return self.data.get((row, col)) is not None

def SetValue(self, row, col, value):#给表赋值

self.data[(row,col)] = value

# the table can also provide the attribute for each cell

def GetValue(self, row, col):

value = self.data.get((row, col))

if value is not None:

return value

else:

return ''

#return self.datas[row][col]

pass

def GetAttr(self, row, col, kind):

attr = [self.even, self.odd][row % 2]

attr.IncRef()

return attr

这段代码可以自由保存。但是有一点就是要把这两个文件保存在一个文件夹内。

#-*- encoding:UTF-8 -*-

import wx

import wx.grid

from sizers_data_001 import StudentInfoGridTable

class TestFrame(wx.Frame):

def __init__(self):

wx.Frame.__init__(self, None, title="Simple Grid",

size=(640,480))

grid = wx.grid.Grid(self)

table = StudentInfoGridTable()

#这个表是从别的地方创建的类。

grid.SetTable(table, True)

#使用settable的方式来创建表格类。

if __name__ == '__main__':

app = wx.App()

frame = TestFrame()

frame.Show()

app.MainLoop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值