简体   繁体   中英

How to show a list in a listctrl in wxpython

eg:

self.reportList.InsertColumn(0, "Column 0")
self.reportList.InsertColumn(1, "Column 1")
self.reportList.InsertColumn(2, "Column 2")
self.reportList.InsertColumn(3, "Column 3")
self.reportList.SetColumnWidth(0, 100)
self.reportList.SetColumnWidth(1, 100)
self.reportList.SetColumnWidth(2, 100)
self.reportList.SetColumnWidth(3, 100)
listexample = ["11/12/14", "123", "1234", "also", "dude", "foo", "bar", "dodge"] 

How do I get every string of the list displayed in the listctrl so the first row of the listctrl is like

"11/12/14 123 1234 also"

and the second row is like "dude foo bar dodge"

    i = 0
    for i in range(0, len(thelist), 4):                
        self.reportList.InsertStringItem(self.index, thelist[i])
        self.reportList.SetStringItem(self.index, 1, thelist[i+1])
        self.reportList.SetStringItem(self.index, 2, thelist[i+2])
        self.reportList.SetStringItem(self.index, 3, thelist[i+3])
        self.index += 1

This seems to work, but for some reason there is an error that says "IndexError: list index out of range"

Edit: changed stop to "len(thelist)-1". Worked perfectly now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM