https://www.tutorialspoint.com/pyqt/pyqt_qlineedit_widget.htm
# -*- coding: utf-8 -*-"""Created on %(date)s @author: %(username)s"""import sys from PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import * class window(QWidget): def __init__(self): super(window, self).__init__() self.initUI() def initUI(self): self.e1 = QLineEdit() self.e1.setValidator(QIntValidator()) self.e1.setMaxLength(4) self.e1.setAlignment(Qt.AlignRight) self.e1.setFont(QFont("Arial", 20)) self.e2 = QLineEdit() self.e2.setValidator(QDoubleValidator(0.99, 99.99, 2)) flo = QFormLayout() flo.addRow("integer validator", self.e1) flo.addRow("Double validator", self.e2) self.e3 = QLineEdit() self.e3.setInputMask('+99_9999_999999') flo.addRow("Input Mask", self.e3) self.e4 = QLineEdit() self.e4.setInputMask('99999') self.e4.setText("0") self.e4.textChanged.connect(self.textchanged) self.e4.textChanged.connect(self.checkText1) flo.addRow("Text changed", self.e4) self.e44 = QLineEdit() self.e44.setValidator(QIntValidator(1, 5000)) self.e44.setText("5000") self.e44.textChanged.connect(self.checkText2) flo.addRow("Text checked", self.e44) self.e5 = QLineEdit() self.e5.setEchoMode(QLineEdit.Password) flo.addRow("Password", self.e5) self.e6 = QLineEdit("Hello Python") self.e6.setReadOnly(True) flo.addRow("Read Only", self.e6) self.e5.editingFinished.connect(self.enterPress) self.setLayout(flo) self.setWindowTitle("PyQt") def textchanged(self,text): print ("contents of text box: " + text) def enterPress(self): print ("edited") def checkText1(self, text): if text and float(text) >= int(self.e44.text()): self.errorDiag = QErrorMessage() self.errorDiag.showMessage("should smaller than e44") def checkText2(self,text): if text and float(text) <= int(self.e4.text()): self.errorDiag=QErrorMessage() self.errorDiag.showMessage("should smaller than e4") if __name__ == '__main__': app = QApplication(sys.argv) win=window() win.show() sys.exit(app.exec_())