我在python中创建一个密码系统,并希望通过输入输入密码,但在输入时显示为星号。有没有办法做到这一点?
答案 0 :(得分:0)
提供你在窗口:
import msvcrt #for getch
import sys
password = list()
while 1:
char = msvcrt.getch()#read one char without pressing enter
password.append(str(char))#append the character to the password
if ord(char) == 13:#if user presses enter break loop
break
if ord(char) == 8:#if user presses backspace
password.pop()#delete password's last character
sys.stdout.write("/b")#erase one * from console
continue#do not write next *
sys.stdout.write("*")#write * at the place of the character
希望这有帮助