Making items visible in wxPython wxListCtrl

Greg Krohn greg at invalid.invalid
Tue May 18 17:43:06 EDT 2004


Piet wrote:
> Hi there.
> I am trying to display tabular data in a wxListCtrl. What I get from
> ...

I hope this clears it up.


from wxPython.wx import *
class MainWindow(wxFrame):
     def __init__(self,parent,id,title):
         wxFrame.__init__(self,parent,-1, title,
                          style=wxDEFAULT_FRAME_STYLE)
         self.panel = wxPanel(self,-1)
         self.Lctrl = wxListCtrl(self.panel,-1,
                             size=(200,200),style =wxLC_REPORT)

#        for i in range(2):
#            self.Lctrl.InsertColumn(i, "Column"+str(i),
#                        format=wxLIST_FORMAT_LEFT,width=100)
#            self.Lctrl.SetStringItem(i,1,"Hi")
#            self.Lctrl.SetStringItem(i,2,"there")
#            self.Lctrl.SetItemData(i,1)

         self.Lctrl.InsertColumn(0, "Name")
         self.Lctrl.InsertColumn(1, "ID")
         self.Lctrl.InsertColumn(2, "Spam Level")

         people = [["George", "3t4d3", "5"],
                   ["Beth", "34g245", "3"],
                   ["Zaphod", "424242", "42"]]

         # Notice you use InsertStringItem for the first item
         # in the row and then use SetStringItem for the rest
         for index, (name, id, spam) in enumerate(people):
             self.Lctrl.InsertStringItem(index, name)
             self.Lctrl.SetStringItem(index, 1, id)
             self.Lctrl.SetStringItem(index, 2, spam)


app = wxPySimpleApp()
frame = MainWindow(None, -1, "List Control Test")
frame.Show(1)
app.MainLoop()



 > Best regards
 >
 > Peter

Ditto,
greg




More information about the Python-list mailing list