wxpython Checklistbox with integers

56 Views Asked by At

I am using a checklistbox as a filter and cannot get it to work when there are integers in the list. I have tried converting to a string and still get an error. Any suggestions on how I can get this to work?

list1 works fine list2 = Item at index 0 has type 'int' but a sequence of bytes or strings is expected testlist1 and testlist2: CheckListBox(): arguments did not match any overloaded call: overload 1: argument 5 has unexpected type 'str' overload 2: too many arguments

import wx

class MyFrame(wx.Frame):
 
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"Multi-mode testing hot patch tool",size = (800,600))
        panel = wx.Panel(self)
        list1 = ["one","two" ,"three"]
        list2 = [1, 2, 3]
        testlist1 = ','.join(map(str, list2))
        testlist2 = ''.join(str(e) for e in list2)
        
        self.listbox3 = wx.CheckListBox(panel,-1,(300,80),(200, 60),list1)

 
if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()
1

There are 1 best solutions below

0
Rolf of Saxony On

You are not constructing your list properly.

Take a look at the results of printing out your constructs and then testlist3 below:

1,2,3
123
['1', '2', '3']


import wx

class MyFrame(wx.Frame):
 
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"Multi-mode testing hot patch tool",size = (800,600))
        panel = wx.Panel(self)
        list1 = ["one","two" ,"three"]
        list2 = [1, 2, 3]
        testlist1 = ','.join(map(str, list2))
        print(testlist1)
        testlist2 = ''.join(str(e) for e in list2)
        print(testlist2)
        testlist3 = [str(i) for i in list2]
        print(testlist3)
        
        self.listbox3 = wx.CheckListBox(panel,-1,(300,80),(200, 60),testlist3)

 
if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

enter image description here