How to have password echoed as asterisks

后端 未结 2 431
我在风中等你
我在风中等你 2020-11-27 08:04

I am trying to figure out how to prompt for a password, and have the users input echoed back as asterisks (********)

So recently, I took on the project

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 08:20

    You should be able to erase an asterisk by writing the characters \x08 \x08. The \x08 will move the cursor back one position, the space will overwrite the asterisk, then the last \x08 will move the cursor back again, putting it in the correct position to write the next *.

    I don't know off the top of my head how to determine when a backspace is typed, but you can do that easily: just add something like print repr(x) after you've called x = msvcrt.getch(), then start your program and hit backspace.

提交回复
热议问题