[python]PyQt5- QLineEdit

1.回显模式(EchoMode)

(1)Normal(输入什么显示什么)

(2)NoEcho(提交输入给计算机,但不回显)

(3)Password

(4)PasswordEchoOnEdit(先Echo,过一会然后用*代替)

from PyQt5.QtWidgets import *
import sys

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

class testLinEdit_001(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):
        self.setWindowTitle("文本输入框的回显模式")
        # 表单布局
        formlayout = QFormLayout()

    #常规回显Normal
        # 创建控件
        normalLineEdit = QLineEdit()
        # 把文本放到布局里去
        formlayout.addRow("Normal",normalLineEdit)
        # placeholdertext在文本输入没有任何东西时,默认显示的文字
        normalLineEdit.setPlaceholderText("Normal")
        # 设置回显
        normalLineEdit.setEchoMode(QLineEdit.Normal)

    #常规回显NoEcho
        # 创建控件
        noEchoLineEdit = QLineEdit()
        # 把文本放到布局里去
        formlayout.addRow("NoEcho",noEchoLineEdit)
        # placeholdertext在文本输入没有任何东西时,默认显示的文字
        noEchoLineEdit.setPlaceholderText("NoEcho")
        # 设置回显
        noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)

    #常规回显Password
        # 创建控件
        passwordLineEdit = QLineEdit()
        # 把文本放到布局里去
        formlayout.addRow("Password",passwordLineEdit)
        # placeholdertext在文本输入没有任何东西时,默认显示的文字
        passwordLineEdit.setPlaceholderText("Password")
        # 设置回显
        passwordLineEdit.setEchoMode(QLineEdit.Password)

    #常规回显PasswordEchoOnEditEcho
        # 创建控件
        passwordEchoOnEditEcho = QLineEdit()
        # 把文本放到布局里去
        formlayout.addRow("PasswordEchoOnEdit",passwordEchoOnEditEcho)
        # placeholdertext在文本输入没有任何东西时,默认显示的文字
        passwordEchoOnEditEcho.setPlaceholderText("PasswordEchoOnEdit")
        # 设置回显
        passwordEchoOnEditEcho.setEchoMode(QLineEdit.PasswordEchoOnEdit)

        # 应用表单布局
        self.setLayout(formlayout)

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

猜你喜欢

转载自www.cnblogs.com/dandanduba/p/12508941.html