# if getch module is available, then we implement our own getpass() with asterisks,
# otherwise we just use the plain boring getpass.getpass()
try:
import getch
def getpass(prompt):
"""Replacement for getpass.getpass() which prints asterisks for each character typed"""
print(prompt, end='', flush=True)
buf = ''
while True:
ch = getch.getch()
if ch == '\n':
print('')
break
else:
buf += ch
print('*', end='', flush=True)
return buf
except ImportError:
from getpass import getpass
如果您使用的是Tkinter:(这是Python2.x,但是,3.x会非常相似)
在外壳中,这是不可能的。但是,您可以编写一个函数来存储输入的文本,并在调用时只报告一个*字符串。 Kinda like this,我没有写。我只是用谷歌搜索了一下。
你可以这样做:
这里有^{} ,一个函数隐藏用户输入。
相关问题 更多 >
编程相关推荐