开发者

Adding data to wxlistbox

How do I add data to an item in a wxlistbox control?

Lets say I have a record of items, I wanna add their id from the database as the data of the item:

Label   Data
--------------
开发者_如何学GoShoes   1
Watch   2
Bags    3


You can either add the items when you create the list, or append them later. Items are added as a list of strings. The following example shows items being added each way.

import wx

app = wx.App()
frame = wx.Frame(parent=None, id=-1, title = "Test List Box",size=(200,300) )
panel = wx.Panel(frame)

lb = wx.ListBox(panel,-1,(20,20),(100,200),["Shoes  1","Watch  2"])
lb.InsertItems(["Bags    3","Hats     5"],2)

frame.Show()
app.MainLoop()


Use wx.listctrl instead. That permits multiple columns.


I wrote something up about this:

http://www.blog.pythonlibrary.org/2010/12/16/wxpython-storing-object-in-combobox-or-listbox-widgets/

That should get you going.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜