wxListCtrl Deprications

I am having problems going from the wxPythonListCtrlExample:

to my own code…I am seeing a lot of deprication warnings and cannot find the new methods or attributes to use to get past the depricated warnings & errors. My code below:

88 self.list_ctrl = wx.ListCtrl(self.panel, size=(-1,100), style=wx.LC_REPORT| wx.BORDER_SUNKEN)
93 self.list_ctrl.InsertColumn(0, ‘Type’)
94 self.list_ctrl.InsertColumn(1, ‘Status’)
95 self.list_ctrl.InsertColumn(2, ‘Last Action’, width=125)
96 self.list_ctrl.InsertColumn(3, ‘Interval’)

96 self.list_ctrl.InsertStringItem(1,0, ‘MAXX’)
97 self.list_ctrl.InsertStringItem(1,1, ‘Running’)
98 self.list_ctrl.InsertStringItem(1,2, ‘Started’)
99 self.list_ctrl.InsertStringItem(1,3, ‘1s’)

This code will not even run even though I copied it from the example that did and only changed the text.

The console output I get is below:

TypeError: ListCtrl.InsertItem(): arguments did not match any overloaded call:
“filename.py”, line 96, in init
overload 1: argument 2 has unexpected type ‘int’
overload 2: argument 3 has unexpected type ‘int’
overload 3: too many arguments
overload 4: argument 3 has unexpected type ‘int’

Thoughts on what I may be missing?

Which versions of wxPython and Python do you use ?

How do I find out wxPython version?

Python 3.7.4 64bit (amd)
wxPython3.0.5 64bit.

Took me a minute to figure it out.

Is there a good reason you do not use wxPython 4.x version ?

No reason better than I just kept using the same version I got working initially. So do I just do

pip install -U wxPython ??

It should work :slight_smile:

After running it, I still have the same version…not sure what to do about that, I would like to update it if there is a next stable version…

After the update, it worked this time, I am still getting the deprecation errors. Such as:

self.list_ctrl.SetStringItem(self.index, 1, ‘Running’)
.\listCtrlTest.py:line#: wxPyDeprecationWarning: Call to deprecated item. Use SetItem instead

After this warning, I tried to use the setItem, but then it complains that it wants InsertItem. Using InsertItem then gets an error that there is no InsertItem call matching what I have supplied. I’m still using the original example code and changing the listCtrl.method_call each time the interpreter complains…

If you don’t have it already, grab a copy of the demo at https://extras.wxpython.org/wxPython4/extras/. Get the one from the subfolder that matches the version of wxPython you are using, unarchive it, and run demo/demo.py. The demo contains sample usages of most of the widgets in wxPython. In the one for ListCtrl you can see that it first adds a new item with InsertItem and then sets values for the remaining columns using SetItem.

Also, the class is documented here:



Thank you. I’ll be able to get into this today and reply to the thread about results…


Still back to the same problem as before, cannot insert row data:

import wx
import mysql.connector

cnx = None

class MyForm(wx.Frame):

    index = 0

    def __init__(self):
      wx.Frame.__init__(self, None, wx.ID_ANY, title = 'My Form')

      self.panel = wx.Panel(self, wx.ID_ANY)
      self.bmp1 = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16))
      titleIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
      title = wx.StaticText(self.panel, wx.ID_ANY, 'mySQL Connect Test')
      self.bmp2 = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (16, 16))
      inputOneIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp2)
      lblHost = wx.StaticText(self.panel, wx.ID_ANY, 'Hostname:')
      self.txtHost = wx.TextCtrl(self.panel, wx.ID_ANY, 'localhost')
      inputTwoIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
      lblUSN = wx.StaticText(self.panel, wx.ID_ANY, 'Username')
      self.txtUSN = wx.TextCtrl(self.panel, wx.ID_ANY, '')
      inputThreeIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
      lblPWD = wx.StaticText(self.panel, wx.ID_ANY, 'Password', style = wx.TE_PASSWORD)
      self.txtPWD = wx.TextCtrl(self.panel, wx.ID_ANY, '', style = wx.TE_PASSWORD)
      inputFourIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
      lblSchema = wx.StaticText(self.panel, wx.ID_ANY, 'Default Schema:')
      self.txtSchema = wx.TextCtrl(self.panel, wx.ID_ANY, '')
      lblStatus = wx.StaticText(self.panel, wx.ID_ANY, 'Status:')
      self.txtStatus = wx.TextCtrl(self.panel, wx.ID_ANY, 'Disconnected...')
      self.okBtn = wx.Button(self.panel, wx.ID_ANY, 'OK')
      self.cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel')
      self.btnConnect = wx.Button(self.panel, wx.ID_ANY, 'Connect')
      self.btnDisconnect = wx.Button(self.panel, wx.ID_ANY, 'Disconnect')
      self.Bind(wx.EVT_BUTTON, self.onOK, self.okBtn)
      self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelBtn)
      self.Bind(wx.EVT_BUTTON, self.onTryConnect, self.btnConnect)
      self.list_ctrl = wx.ListCtrl(self.panel, size=(-1,100),
      self.list_ctrl.InsertColumn(0, 'Type')
      self.list_ctrl.InsertColumn(1, 'Status')
      self.list_ctrl.InsertColumn(2, 'Last')
      self.list_ctrl.InsertColumn(3, 'Interval')

      topSizer = wx.BoxSizer(wx.VERTICAL)
      titleSizer = wx.BoxSizer(wx.HORIZONTAL)
      gridSizer = wx.BoxSizer(wx.HORIZONTAL)
      inputOneSizer = wx.BoxSizer(wx.HORIZONTAL)
      inputTwoSizer = wx.BoxSizer(wx.HORIZONTAL)
      inputThreeSizer = wx.BoxSizer(wx.HORIZONTAL)
      nputFourSizer = wx.BoxSizer(wx.HORIZONTAL)
      inputFourSizer = wx.BoxSizer(wx.HORIZONTAL)
      inputFiveSizer = wx.BoxSizer(wx.HORIZONTAL)
      btnSizer1 = wx.BoxSizer(wx.HORIZONTAL)
      btnSizer2 = wx.BoxSizer(wx.HORIZONTAL)

      titleSizer.Add(titleIco, 0, wx.ALL, 5)
      titleSizer.Add(title, 0, wx.ALL, 5)
      gridSizer.Add(self.list_ctrl, 0, wx.ALL, 5)
      inputOneSizer.Add(inputOneIco, 0, wx.ALL, 5)
      inputOneSizer.Add(lblHost, 0, wx.ALL, 5)
      inputOneSizer.Add(self.txtHost, 1, wx.ALL | wx.EXPAND, 5)
      inputTwoSizer.Add(inputTwoIco, 0, wx.ALL, 5)
      inputTwoSizer.Add(lblUSN, 0, wx.ALL, 5)
      inputTwoSizer.Add(self.txtUSN, 1, wx.ALL | wx.EXPAND, 5)
      inputThreeSizer.Add(inputThreeIco, 0, wx.ALL, 5)
      inputThreeSizer.Add(lblPWD, 0, wx.ALL, 5)
      inputThreeSizer.Add(self.txtPWD, 1, wx.ALL | wx.EXPAND, 5)
      inputFourSizer.Add(inputFourIco, 0, wx.ALL, 5)
      inputFourSizer.Add(lblSchema, 0, wx.ALL, 5)
      inputFourSizer.Add(self.txtSchema, 1, wx.ALL | wx.EXPAND, 5)
      inputFiveSizer.Add(lblStatus, 0, wx.ALL, 5)
      inputFiveSizer.Add(self.txtStatus, 0, wx.ALL, 5)
      btnSizer1.Add(self.okBtn, 0, wx.ALL, 5)
      btnSizer1.Add(self.cancelBtn, 0, wx.ALL, 5)
      btnSizer2.Add(self.btnConnect, 0, wx.ALL, 5)
      btnSizer2.Add(self.btnDisconnect, 0, wx.ALL, 5)
      topSizer.Add(titleSizer, 0, wx.CENTER)
      topSizer.Add(gridSizer, 0, wx.CENTER)
      topSizer.Add(wx.StaticLine(self.panel, ), 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(inputOneSizer, 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(inputTwoSizer, 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(inputThreeSizer, 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(inputFourSizer, 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(inputFiveSizer, 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL | wx.EXPAND, 5)
      topSizer.Add(btnSizer1, 0, wx.ALL | wx.CENTER, 5)
      topSizer.Add(btnSizer2, 0, wx.ALL | wx.CENTER, 5)

      self.list_ctrl.InsertItem(self.index, 0, "Optical")
      self.list_ctrl.SetItem(self.index, 1, "Ready")
      self.list_ctrl.SetItem(self.index, 2, "Start")
      self.index += 1

    def CheckConnection():
        if self.cnx != None:
            if cnx.is_connected(): print("\n Connected ? : YES")
            self.txtStatus.SetValue("Not Connected")
            print("\n Connected ? : NO")

            dictConnInfo = {'user': self.txtUSN.GetValue(),
                    'password': self.txtPWD.GetValue(),
                    'host': sel.txtHost.GetValue(),
                    'database': self.txtSchema.GetValue()

            cnx = mysql.connector.connect( ** dictConnInfo)
            if cnx.is_connected():
                print("\n Connected ? : YES")
                self.txtStatus.SetValue("Connected?: YES")
                print("\n Connected ? : NO")
                self.txtStatus.SetValue("Connected?: NO")
                if cnx.is_connected():
                    print("\n Connected ? : YES")

    def onOK(self, event):

    def onTryConnect(self, event):
        self.txtStatus.SetValue("Connected?: NO")

        dictConnInfo = {'user': self.txtUSN.GetValue(),
                'password': self.txtPWD.GetValue(),
                'host': self.txtHost.GetValue(),
                'database': self.txtSchema.GetValue()
        cnx = mysql.connector.connect( ** dictConnInfo)
        if cnx.is_connected():
            print("\n Connected ? : YES")
            self.txtStatus.SetValue("Connected?: YES")
            print("\n Connected ? : NO")
            self.txtStatus.SetValue("Connected?: NO")
        if cnx.is_connected():
            print("\n Connected ? : YES")
            self.txtStatus.SetValue("Connected?: YES")

    def onCancel(self, event):

    def closeProgram(self, event):

if __name__ == '__main__':
    app = wx.App()
    frame = MyForm().Show()

The lines for adding/inserting rows into the grid are taken straight from the demo.py for my version.

Try this on line 95:

      self.list_ctrl.InsertItem(self.index, "Optical")

You were passing an extra integer. As can be seen in the docs, the 2nd overload of InsertItem takes just the index and the string. Which is what this traceback was trying to tell you:

Traceback (most recent call last):
  File "leifpy", line 160, in <module>
    frame = MyForm().Show()
  File "leif.py", line 96, in __init__
    self.list_ctrl.InsertItem(self.index, 0, "Optical")
TypeError: ListCtrl.InsertItem(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'int'
  overload 2: argument 2 has unexpected type 'int'
  overload 3: too many arguments
  overload 4: argument 2 has unexpected type 'int'

So that works on line 95,forinserting into 0, 0, how do I put text into the other columns?Repeating line 95 just keeps appending lines into the first column

@Robin, I believe I found the solution:

It appears to be that InsertItem must be called to insert a row and possibly the first column first. After callingInsertItem(), SetItem can then be called on existing rows…For example, this works:

  row = [ "Sorter 1", 'Optical', 'Running', "Started", "1s"]

  self.list_ctrl.InsertItem(self.index, row[0])
  self.list_ctrl.SetItem(self.index,1, row[2])
  self.list_ctrl.SetItem(self.index,2, row[2])
  self.list_ctrl.SetItem(self.index,3, row[3])

This will faile if I do not call InsertItem first…

I am now trying to Iterate the list contained in list_strl to color backgrounds of cells with “Running” as text with green and possibly other text in other colors…GetItemCount() apparently cannot be used, GetItemText also…trying to find some API docs I can trust…

Unfortunately, I am not making progress on the background color and iteration of list items. Hopefull this error can help direct:

AttributeError: 'ListCtrl' object has no attribute 'SetItemBackgroundColor'
Try :


That worked Colour thanks! Any thoughts about enumerating the list so I can check for other colorization needed?