https://wiki.wxpython.org/GridCellChoiceEditor

#-----------------------------------------------------------------------------
# Name: GridCombo.py # Purpose: Dynamic list updating with a wx.grid.GridCellChoiceEditor # # Author: Thomas M Wetherbee # # Created: 2009/04/27 # RCS-ID: $Id: GridCombo.py $ # Copyright: (c) 2009 # Licence: Distributed under the terms of the GNU General Public License #----------------------------------------------------------------------------- #!/usr/bin/env python   ''' Dynamic list updating with a wx.grid.GridCellChoiceEditor.  This example shows how to dynamically update the choices in a GridCellChoiceEditor. This simple example creates a two column grid where the top row in each column is a wx.grid.GridCellChoiceEditor. The choices listed in the editor are created on the fly, and may change with each selection. Text entered into the GridCellChoiceEditor cell is appended as an additional choice.  In addition to appending new choices, this example also shows how to get the selection index and client data from the choice.  Cell editor interactions are printed for every step.  This example is deliberately simple, lacking sizers and other useful but confusing niceties.  Theory:  The GridCellChoiceEditor uses an underlying ComboBox to do the editing. This underlying ComboBox is created when the cell editor is created. Normally the ComboBox is completely hidden, but in this example we retrieve a reference to the ComboBox and use it to load choices and retrieve index and client data.  The example starts with a GridCellChoiceEditor attached to the two top cells of the grid. When the GridCellChoiceEditor is invoked for the first time, two choice items are added to the choice list along with their associated user data. The items are ('spam', 42) and ('eggs', 69), where spam is the text to display and 42 is the associated client data. In this example 'spam' has an index of 0 while eggs, being the second item of the list, has an index of 1.  Note that the index and user data are not required. The demonstrated method works fine without either, but sometimes it is useful to know the index of a selection, especially when the user is allowed to create choices. For example, we might have the list ['spam', 'eggs', 'spam', 'spam'] where the three spam items are different objects. In this case simply returning the item value 'spam' is ambiguous. We need to know the index, or perhaps some associated client data.  In our example, when the user enters a new choice, the choice is appended to the end of the choice list. A unique integer number is created for each new choice, in succession, with the first number being 100. This number is used for client data.  In this example we bind directly to the ComboBox events, rather than getting the events through the frame. This is done to keep the grid from eating the events. The difference in binding can be seen in the two binding methods: 

转载于:https://www.cnblogs.com/chengxuyuan326260/p/6391471.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值