Input dialog in PyQt is supported out of the box (QInputDialog). This has an input text, an ok and cancel button.

In this article you’ll see that works in PyQt. As shown in the screenshot

pyqt input dialog

Download Examples:
Download PyQt examples

Input Dialog


The code below creates a PyQt input dialog. After you click the button, you can enter some text. The text is shown as label.

The dialog is created in the method showDialog and it’s just a few lines. Input dialig is part of PyQt5.QtWidgets.

from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QInputDialog, QApplication, QLabel)
import sys

class Example(QWidget):

def __init__(self):

def initUI(self):
# Add button
self.btn = QPushButton('Show Input Dialog', self)
self.btn.move(30, 20)

# Add label
self.le = QLabel(self)
self.le.move(30, 62)

self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Input dialog')

def showDialog(self):
text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter text:')
if ok:

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()