Search code examples
pythonpyqt5qcombobox

Adding INT values in combo box in Python


i'm basically trying to add values 1-100 in combo box but i'm unable to do so

for i in range(1,100):
    rollno_list = []
    rollno_list.append(i)

combo_roll = QComboBox()
combo_roll.addItems([str(rollno_list)])

Solution

  • You are adding a list with a single element that is a string, instead you must convert each element to a string:

    combo_roll.addItems([str(e) for e in range(1, 100)])
    

    Also in the for-loop you are creating a list in each iteration where you add a new element which is an error.