Password form in PyQt

Question:

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)
Asked By: Margarita Gonzalez

||

Answers:

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.

Answered By: falsetru

In PyQt5:

self.LeUsuario.setEchoMode(QtWidgets.QLineEdit.Password)
Answered By: Edwin Paz ss. –

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)
Answered By: Hrvoje

Just add the following line

self.textPass.setEchoMode(QtWidgets.QLineEdit.Password)
Answered By: Bijesh Mohan

In PyQt6:

entry_passsword = QLineEdit()
entry_passsword.setEchoMode(QLineEdit.EchoMode.Password)
Answered By: user21447299
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.