想隐藏" *"键入的密码。但密码显示为原始文本......
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)
答案 0 :(得分:2)
QLineEdit
班级有several modes,可让您控制文字的显示方式。要仅显示星号(*
),请执行以下操作:
self.password = QLineEdit()
self.password.setEchoMode(QLineEdit.Password)
...
output = self.password.text()
PS:
要设置其他密码字符,可以使用此样式表属性:
self.password.setStyleSheet('lineedit-password-character: 9679')
该数字是一个unicode代码点,在本例中是黑色圆圈(●
)。