A Listbox (
QListWidget) presents several options. You can click on an item. An example of a listbox would be a song playlist. Unlike a combobox it shows all possible options.
The screenshot below shows a PyQt list box in a window.
Related Course: Create GUI Apps with Python PyQt5
A listbox widget is created with
QListWidget(), it creates an item-based list widget. The QListWidget provides a list view similar to the one supplied by QListView, but with a classic item-based interface. With a single line a listwidget is added to a window:
self.listwidget = QListWidget()
An item is then added with the method .insertItem(). For example:
self.listwidget.insertItem(0, "Red") where the first parameter is the index. You can add many items that way:
Now if you click on any of the items it won’t do anything. So you need to event the slot to a function call. You can do that with the line:
Where clicked() is a slot or method that is called (a callback method).
The click event is added with the method clicked,
This example below shows how to use the list widget (QListWidget) in PyQt.
from PyQt5.QtWidgets import *
If you are new to Python PyQt, then I highly recommend this book.