您的列表 actualrules 在其中一个字符串中有一个单引号,因此您应该用双引号将其括起来,如下所示。
actualrules = ['Hello World', 'Goodbye Universe',
"Let's go to the mall"]
在您的 for 循环中,我成为列表的每个项目,然后您通过执行 i[0] 仅获取第一个字母
以下是您的列表的一个工作示例
import sys
import wx
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(TestFrame, self).__init__(*args, **kwargs)
actualrules = ['Hello World', 'Goodbye Universe',
"Let's go to the mall"]
panel = wx.Panel(self)
self.list = wx.ListCtrl(panel, size=(1000, 1000), style=wx.LC_REPORT)
self.list.InsertColumn(0, 'Rules')
for i in actualrules:
self.list.InsertStringItem(sys.maxint, i)
pSizer = wx.BoxSizer(wx.VERTICAL)
pSizer.Add(self.list, 0, wx.ALL, 5)
panel.SetSizer(pSizer)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.Add(panel, 1, wx.EXPAND)
self.SetSizer(vSizer)
if __name__ == '__main__':
wxapp = wx.App(False)
testFrame = TestFrame(None)
testFrame.Show()
wxapp.MainLoop()