Python Forum
[PyQt] populate a QListWidget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] populate a QListWidget
#1
Hi

i want to populate a list widget but it always gives me this error

what can i do?

thanks

error:
Quote:TypeError: addItems(self, Iterable[str]): argument 1 has unexpected type 'str'

code

from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton
from PyQt5 import uic
import sys

from PyQt5.QtWidgets import *



class UI(QMainWindow):
    def __init__(self):
        super(UI, self).__init__()

        uic.loadUi("teste3.ui", self)

        self.button = self.findChild(QPushButton, "pushButton")
        
        self.button.clicked.connect(self.clicker)

        


     

        self.show()

    def clicker (self):
        fruits = ("babana", "orange", "apple")

        self.listWidget = QListWidget()



        for fruit in fruits:
            self.listWidget.addItems(str(fruit))


app = QApplication(sys.argv)
UIWindow = UI()
app.exec_()
thanjs
Reply
#2
Post the entire error message. Including the trace. You should not force others to read your code when you can easily provide a concise description of what the error is and where it happened.

The error is very clear. It expects an iterable(str), and you are passing a str. Do you have an iterable thing (like a list perhaps) of strs? You do.
self.listWidget.addItems(fruits)
If you really want to use a list to add items one at a time, you can use self.labelWidget.addItem(str).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get the color name of qlistwidget? flash77 5 1,193 Aug-13-2023, 07:01 PM
Last Post: flash77
  QListWidget, no item was selected flash77 4 925 Aug-02-2023, 09:31 AM
Last Post: Axel_Erfurt
  GUI Problem / call another function / fill QListwidget flash77 5 836 Jul-30-2023, 04:29 PM
Last Post: flash77
  [PyQt] [Solved]Populate ComboBox with for loop? Extra 3 2,056 Jul-31-2022, 09:01 PM
Last Post: Extra
  Problems getting tk Combobox contents to populate properly dford 4 3,711 Jan-08-2022, 02:39 PM
Last Post: dford
  Auto populate dictionary with names/values of QT widgets cjh 1 2,899 Mar-23-2021, 02:56 PM
Last Post: deanhystad
Question [PyQt] CSS Styling for a QLabel inside a QListWidget Alfalfa 2 5,053 Nov-30-2020, 02:59 AM
Last Post: Alfalfa
  [PyQt] How to populate a treeview on a GUI with a dictionary mart79 1 8,157 Aug-05-2019, 01:30 PM
Last Post: Denni
  Why QListWidget doesn't show new line? AlekseyPython 3 3,318 Feb-05-2019, 02:23 PM
Last Post: AlekseyPython
  populate list with images and be able to select them ricardons 0 2,106 Jan-11-2019, 03:45 PM
Last Post: ricardons

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020