5

Want to hide password typed by "*". But the password is appearing as original text...

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)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Aniruddh Chaudhari
  • 113
  • 2
  • 3
  • 9
  • this post will help you : http://stackoverflow.com/questions/3715103/password-field-in-django-model/3715382#3715382 – Sweta Parmar Mar 08 '17 at 13:04

1 Answers1

9

The QLineEdit class has several modes which allow you to control how its text is displayed. To show only asterisks (*), do this:

self.password = QLineEdit()
self.password.setEchoMode(QLineEdit.Password)
...
output = self.password.text()

PS:

To set a different password character, you can use this stylesheet property:

self.password.setStyleSheet('lineedit-password-character: 9679')

The number is a unicode code point, which in this case is for a black circle ().

ekhumoro
  • 115,249
  • 20
  • 229
  • 336