在使用Python的过程中,想输入账号和密码,但是密码会随着输入显示在屏幕上,为了解决这个问题需要用到msvcrt模块
这里是使用代码
importmsvcrt, sysdefpwd_input(a):PRintstr(a),
chars=[]whileTrue:
newChar=msvcrt.getch()ifnewCharin'\r\n':print''
breakelifnewCharin'\b':ifchars:delchars[-1]
sys.stdout.write('\b\b')else:
chars.append(newChar)
sys.stdout.write('*')returnstr(chars)
pwd= pwd_input('passWord:')
这样就解决了显示问题。