在 Python 的组合框中添加 INT 值

Adding INT values in combo box in Python

我基本上是想在组合框中添加值 1-100,但我无法这样做

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

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

您添加的列表中只有一个字符串元素,您必须将每个元素都转换为字符串:

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

同样在 for 循环中,您在每次迭代中创建了一个列表,其中添加了一个错误的新元素。

您正在 for 循环内初始化 rollno_list,因此基本上在 for 循环结束时,您的列表中只有一个数字。

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

    rollno_list.append(i)

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