You can use the TextEditMixin
import wx
from wx.lib.mixins.listctrl import TextEditMixin
class EditableTextListCtrl(wx.ListCtrl, TextEditMixin):
def __init__(self, parent, ID, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
TextEditMixin.__init__(self)
class MyDialog(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id)
listCtrl = EditableTextListCtrl(self, -1, style=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES, size=(300, 200))
listCtrl.InsertColumn(0, 'State')
listCtrl.InsertColumn(1, 'Capital')
listCtrl.SetColumnWidth(0, 140)
listCtrl.SetColumnWidth(1, 153)
states = ['Slovakia', 'Poland', 'Hungary']
capitals = ['Brastislava', 'Warsaw', 'Budapest']
for i in range(3):
listCtrl.InsertStringItem(0, states[i])
listCtrl.SetStringItem(0, 1, capitals[i])
class MyApp(wx.App):
def OnInit(self):
dia = MyDialog(None, -1, 'capitals.py')
dia.ShowModal()
dia.Destroy()
return True
app = MyApp(0)
app.MainLoop()