Open In App
Related Articles

PyQt5 – How to add multiple items to the ComboBox ?

Improve Article
Save Article
Like Article

In this article we will see how we can add multiple items to the combo box at single time. We know we can add item to the combo box with the help of addItem method but this method add only single item at a time. In order to add multiple items at a single time we have to use addItems method which will add all the items at once instead of one by one.

Syntax : combo_box.addItems(item_list)
Argument : It takes list as argument
Action performed : It will add all the list item to the combo box 

Below is the implementation – 


# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # calling method
        # showing all the widgets
    # method for widgets
    def UiComponents(self):
        # creating a combo box widget
        combo_box = QComboBox(self)
        # setting geometry of combo box
        combo_box.setGeometry(200, 150, 120, 30)
        # geek list
        geek_list = ["Geek", "Geeky Geek", "Legend Geek", "Ultra Legend Geek"]
        # adding list of items to combo box
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output : 


Last Updated : 24 Jun, 2021
Like Article
Save Article
Similar Reads
Related Tutorials