Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password form in PyQt

Tags:

python

pyqt

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)
like image 580
Margarita Gonzalez Avatar asked May 13 '14 15:05

Margarita Gonzalez


3 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.

like image 200
falsetru Avatar answered Nov 09 '22 12:11

falsetru


In PyQt5:

self.LeUsuario.setEchoMode(QtWidgets.QLineEdit.Password)
like image 4
Edwin Paz ss. - Avatar answered Nov 09 '22 12:11

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)
like image 1
Hrvoje Avatar answered Nov 09 '22 13:11

Hrvoje