PyQt supports autocomplete. If you type in a text box (QLineEdit), it can make suggestions. Those suggestions are recommended from a list.

You may know this from the web, Google search often shows recommendations while you are typing. You can do a similar thing with PyQt.

This example adds auto complete to a QLineEdit text box.

auto complete QLineEdit

image: tabs showing in a pyqt window.

Auto complete

QLineEdit Auto Complete Example

Start by creating a list of options (names) / suggestions. Thencreate a QCompleter, a completer = QCompleter(names).

names = ["Apple", "Alps", "Berry", "Cherry" ]
completer = QCompleter(names)

The  widget is a simpe text box that can be added to your window. You can create a line edit widget with the line self.lineedit = QLineEdit(). The line edit otherwise works as normal.

self.lineedit = QLineEdit()

You can add suggestions (you defined earlier) to the list. The suggestions are added with the line:

self.lineedit.setCompleter(completer)

If you forget the last line, the QCompleter and QLineEdit are not connected, meaning there is no auto completion.

from PyQt5.QtWidgets import *
import sys

class Window(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        layout = QGridLayout()
        self.setLayout(layout)

        # auto complete options
        names = ["Apple", "Alps", "Berry", "Cherry" ]
        completer = QCompleter(names)

        # create line edit and add auto complete
        self.lineedit = QLineEdit()
        self.lineedit.setCompleter(completer)
        layout.addWidget(self.lineedit, 0, 0)

app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())