import sys

from PyQt5.QtWidgets import QWidget, QFormLayout, QPushButton, QLineEdit, QInputDialog, QApplication


class QInputDialogDemo(QWidget):

    def __init__(self):
        super(QInputDialogDemo, self).__init__()
        self.button1 = QPushButton()
        self.button2 = QPushButton()
        self.button3 = QPushButton()
        self.line1 = QLineEdit()
        self.line2 = QLineEdit()
        self.line3 = QLineEdit()
        self.init()

    def init(self):
        self.setWindowTitle('QInputDialog')
        layout = QFormLayout()

        self.button1.setText('get list items')
        layout.addRow(self.button1, self.line1)
        self.button1.clicked.connect(self.get_item)

        self.button2.setText('get text')
        layout.addRow(self.button2, self.line2)
        self.button2.clicked.connect(self.get_text)

        self.button3.setText('get int')
        layout.addRow(self.button3, self.line3)
        self.button3.clicked.connect(self.get_int)

        self.setLayout(layout)

    def get_item(self):
        items = ('A', 'B', 'C', 'D', 'E')
        item, ok = QInputDialog.getItem(self, 'select', 'list', items)  # -> str, bool
        if item and ok:
            self.line1.setText(item)

    def get_text(self):
        text, ok = QInputDialog.getText(self, 'text input', 'input:')
        if text and ok:
            self.line2.setText(text)

    def get_int(self):
        number, ok = QInputDialog.getInt(self, 'number box', 'input:', min=10, max=100, step=2)
        if number and ok:
            self.line3.setText(str(number))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QInputDialogDemo()
    main.show()
    sys.exit(app.exec_())
