编程语言
首页 > 编程语言> > [python]PyQt5- QLineEdit综合案例

[python]PyQt5- QLineEdit综合案例

作者:互联网

综合应用

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class testLinEdit_003(QWidget):
    def __init__(self):
        super(testLinEdit_003,self).__init__()
        self.initUI()
    
    def initUI(self):
        self.setWindowTitle("LineEdit综合案例")

    # 使用int校验器
        edit1 = QLineEdit()
        edit1.setValidator(QIntValidator())
        edit1.setMaxLength(4)#不超过4位数
        edit1.setAlignment(Qt.AlignRight)#靠右
        edit1.setFont(QFont('Arial',20))

    # 使用浮点数校验器
        edit2 = QLineEdit()
        #最小,最大,小数点后几位
        edit2.setValidator(QDoubleValidator(0.99,99.99,2))

    # 掩码
        edit3 = QLineEdit()
        edit3.setInputMask('99_9999_999999;#')

        # 设置布局
        formLayout = QFormLayout()
        formLayout.addRow('整数校验',edit1)
        formLayout.addRow('浮点数校验',edit2)
        formLayout.addRow('Input mask',edit3)
        self.setLayout(formLayout)

def main(self):
    app = QApplication(sys.argv)
    main = self()
    main.show()
    exit(app.exec_())

if __name__ == "__main__":
    main(testLinEdit_003)
    

 

标签:__,python,self,PyQt5,edit1,QLineEdit,main,formLayout
来源: https://www.cnblogs.com/dandanduba/p/12516419.html