python wxpython wx.grid动态增加行_wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的gri...

这篇博客介绍了如何使用Python的wxPython库创建一个动态的Grid,支持文本、复选框和颜色选择等单元格编辑。通过自定义GridCellColorEditor实现颜色选择功能,允许用户在单元格中设置背景色,并提供了添加、删除行的功能。此外,还展示了如何创建CustomGridTable类来管理数据源,并提供了添加、删除和清空数据的方法。
摘要由CSDN通过智能技术生成

#-*-coding:utf-8

#-------------------------------------------------------------------------------#Name: 模块1#Purpose:#

#Author: ankier#

#Created: 14/10/2012#Copyright: (c) ankier 2012#Licence: #-------------------------------------------------------------------------------

importwx, wx.grid as grd#grid column类型

classGridColumnControlKind:

Text="Text"CheckBox= "CheckBox"Colour= "Colour"

#定购的Grid cell color editor

classGridCellColorEditor(grd.PyGridCellEditor):defCreate(self, parent, id, evtHandler):"""Called to create the control, which must derive from wx.Control.

*Must Override*"""self.__Parent =parent

self.__ColorDialog =None

self.__ColorButton = wx.Button(parent, id, "")

self.SetControl(self.__ColorButton)#添加新的event handler, 防止 弹出窗口后, cell 自动editor

newEventHandler =wx._core.EvtHandler()ifevtHandler:

self.__ColorButton.PushEventHandler(newEventHandler)

self.__ColorButton.Bind(wx.EVT_BUTTON, self.OnClick)defOnClick(self, event):

self.__ColorButton.SetFocus()

self.ShowColorDialog()defSetSize(self, rect):"""Called to position/size the edit control within the cell rectangle.

If you don't fill the cell (the rect) then be sure to override

PaintBackground and do something meaningful there."""self.__ColorButton.SetDimensions(rect.x,rect.y,rect.width+2,rect.height+2,wx.SIZE_ALLOW_MINUS_ONE)defClone(self):"""Create a new object which is the copy of this one

*Must Override*"""

returnGridCellColorEditor()defBeginEdit(self, row, col, grid):"""Fetch the value from the table and prepare the edit control

to begin editing. Set the focus to the edit control.

*Must Override*"""self.startValue=grid.GetTable().GetValue(row, col)

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值