QLineEdit有4種回顯模式(EchoMode):
1.Normal
2.NoEcho
3.Password
4.PasswordEchoOnEdit
from PyQt5.QtWidgets import * import sys class QLineEditEchoMode(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle("文本輸入框的回顯模式") formLayout = QFormLayout() normalLineEdit = QLineEdit() noEchoLineEdit = QLineEdit() passwordLineEdit = QLineEdit() passwordEchoNoEditLineEdit = QLineEdit() formLayout.addRow("normal", normalLineEdit) formLayout.addRow("NoEcho", noEchoLineEdit) formLayout.addRow("Password", passwordLineEdit) formLayout.addRow("PasswordEchoOnEdit", passwordEchoNoEditLineEdit) # placeholdertext設置提示 normalLineEdit.setPlaceholderText("Normal") noEchoLineEdit.setPlaceholderText("NoEcho") passwordLineEdit.setPlaceholderText("Password") passwordEchoNoEditLineEdit.setPlaceholderText("PasswordEchoOnEdit") normalLineEdit.setEchoMode(QLineEdit.Normal) noEchoLineEdit.setEchoMode(QLineEdit.NoEcho) passwordLineEdit.setEchoMode(QLineEdit.Password) passwordEchoNoEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit) self.setLayout(formLayout) if __name__ == '__main__': app = QApplication(sys.argv) main = QLineEditEchoMode() main.show() sys.exit(app.exec_())
運行后結果:
輸入后效果: