wx.ListCtrl简单使用例子

时间:2021-06-10 05:44:26

效果图:

wx.ListCtrl简单使用例子

示例代码:

  1. #! /usr/bin/env python
  2. #coding=utf-8
  3. import wx
  4. import sys
  5. packages = [('jessica alba', 'pomona', '1981'), ('sigourney weaver', 'new york', '1949'),
  6. ('angelina jolie', 'los angeles', '1975'), ('natalie portman', 'jerusalem', '1981'),
  7. ('rachel weiss', 'london', '1971'), ('scarlett johansson', 'new york', '1984' )]
  8. class MyFrame(wx.Frame):
  9. def __init__(self, parent, id, title, size):
  10. wx.Frame.__init__(self, parent, id, title, size)
  11. hbox = wx.BoxSizer(wx.HORIZONTAL)
  12. panel = wx.Panel(self, -1)
  13. self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT)
  14. self.list.InsertColumn(0, 'name', width=140)
  15. self.list.InsertColumn(1, 'place', width=130)
  16. self.list.InsertColumn(2, 'year', wx.LIST_FORMAT_RIGHT, 90)
  17. for i in packages:
  18. index = self.list.InsertStringItem(sys.maxint, i[0])
  19. self.list.SetStringItem(index, 1, i[1])
  20. self.list.SetStringItem(index, 2, i[2])
  21. hbox.Add(self.list, 1, wx.EXPAND)
  22. panel.SetSizer(hbox)
  23. self.Centre()
  24. class MyApp(wx.App):
  25. def OnInit(self):
  26. frame = MyFrame(None, id=-1, title="DownThemAll", size=(800,600))
  27. frame.Show(True)
  28. self.SetTopWindow(frame)
  29. return True
  30. if __name__ == '__main__':
  31. app = MyApp()
  32. app.MainLoop()