Skip to content

Instantly share code, notes, and snippets.

@joranbeasley
Last active September 4, 2015 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joranbeasley/96453c2fe6cb7164dc2f to your computer and use it in GitHub Desktop.
Save joranbeasley/96453c2fe6cb7164dc2f to your computer and use it in GitHub Desktop.
import wx
########################################################################
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.index = 0
self.list_ctrl = wx.ListCtrl(panel, size=(-1,100),
style=wx.LC_REPORT
|wx.LC_NO_HEADER
)
self.clear_all(0)
btn = wx.Button(panel, label="Add Line")
btn2 = wx.Button(panel,label="Clear all")
btn.Bind(wx.EVT_BUTTON, self.add_line)
btn2.Bind(wx.EVT_BUTTON, self.clear_all)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
sizer.Add(btn2, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)
def clear_all(self,evt):
self.list_ctrl.ClearAll()
self.index = 0
self.list_ctrl.InsertColumn(0, 'Subject')
# self.list_ctrl.InsertColumn(1, 'Due')
# self.list_ctrl.InsertColumn(2, 'Location', width=125)
#----------------------------------------------------------------------
def add_line(self, event):
line = "Line %s" % self.index
self.list_ctrl.InsertStringItem(self.index, line)
print "LINE",line
self.Update()
#self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
#self.list_ctrl.SetStringItem(self.index, 2, "USA")
self.index += 1
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment