Hello.
I have a code to delete multiple items from a ListCtrl, but when I run it i have a error (IndexError: pop index out of range
).
How can i repair this code? or there is another beter mode to this word?
import wx
class Program(wx.Frame):
def init(self, parent, title):
super().init(parent,title = title)
self.Center()
self.Show()
self.panel = wx.Panel(self)
self.list = wx.ListCtrl(self.panel, -1, style= wx.LC_REPORT|wx.LC_VRULES)
self.list.InsertColumn(0, ‘Animals’)
self.animals = [‘cat’, ‘duck’, ‘dog’, ‘cow’, ‘bat’, ‘mouse’]
self.button = wx.Button(self.panel, -1, ‘Del’)
self.Bind(wx.EVT_BUTTON, self.delete, self.button)
self.make_list()
def make_list(self):
id = self.list.GetItemCount()
for animal in self.animals:
self.list.InsertStringItem(id, animal)
id = id+1
def delete(self, event):
all = self.list.GetItemCount()
for item in range(0, all - 1):
selected = self.list.IsSelected(item)
if selected == True:
self.animals.pop(item)
self.make_list()
app =wx.App()
Program(None, ‘Title’)
app.MainLoop()