如何在 QLineEdit 中隐藏密码

Ani*_*ari 4 passwords pyside qlineedit python-2.7

想要隐藏“*”键入的密码。但是密码显示为原始文本...

class Form(QDialog):
    def __init__(self, parent = None):
        super(Form,self).__init__(parent)

        self.usernamelabel = QLabel("Username : ")
        self.passwordlabel = QLabel("Password : ")
        self.username = QLineEdit()
        self.password = QLineEdit()
        self.okbutton = QPushButton("Login")
        self.username.setPlaceholderText("Enter Username Here")
        self.password.setPlaceholderText("Enter Password Here")

        layout = QGridLayout()
        layout.addWidget(self.usernamelabel,0,0)
        layout.addWidget(self.passwordlabel,1,0)
        layout.addWidget(self.username,0,1)
        layout.addWidget(self.password,1,1)
        layout.addWidget(self.okbutton)
        self.setLayout(layout)
Run Code Online (Sandbox Code Playgroud)

ekh*_*oro 6

QLineEdit班有几个模式,让你可以控制它的文本的显示方式。要仅显示星号 ( *),请执行以下操作:

self.password = QLineEdit()
self.password.setEchoMode(QLineEdit.Password)
...
output = self.password.text()
Run Code Online (Sandbox Code Playgroud)

PS:

要设置不同的密码字符,您可以使用此样式表属性:

self.password.setStyleSheet('lineedit-password-character: 9679')
Run Code Online (Sandbox Code Playgroud)

该数字是一个 unicode 代码点,在本例中用于黑色圆圈 ( ?)。