12

I made a login form but I don't know how to put ** in the Password field. I only have:

self.textPass = QtGui.QLineEdit(self)
1
  • 1
    try: self.textPass.setEchoMode(QtGui.QLineEdit.Password)
    – jedwards
    Commented May 13, 2014 at 15:06

5 Answers 5

32

As jedwards commented, use setEchoMode method:

example:

from PyQt4 import QtGui, QtCore

app = QtGui.QApplication([])
pw = QtGui.QLineEdit()
pw.setEchoMode(QtGui.QLineEdit.Password)
pw.show()
app.exec_()

See also QLineEdit.EchoMode enum.

8

In PyQt5:

self.LeUsuario.setEchoMode(QtWidgets.QLineEdit.Password)
1
  • This is a very good standalone example. It works without needing qtwidgets, which saves drive space.
    – Jacob Ward
    Commented Apr 10, 2021 at 20:21
1

PyQT5 solution with option to hide/reveal typed content

Install:

pip install qtwidgets

Then you can use:

from PyQt5 import QtCore, QtGui, QtWidgets
from qtwidgets import PasswordEdit


class Window(QtWidgets.QMainWindow):

    def __init__(self):
        super().__init__()

        password = PasswordEdit()
        self.setCentralWidget(password)


app = QtWidgets.QApplication([])
w = Window()
w.show()
app.exec_()

Taken from

Another solution (for PyQT5):

password = QtWidgets.QLineEdit()
password.setEchoMode(QLineEdit.Password)
1

Just add the following line

self.textPass.setEchoMode(QtWidgets.QLineEdit.Password)
0

In PyQt6:

entry_passsword = QLineEdit()
entry_passsword.setEchoMode(QLineEdit.EchoMode.Password)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.