Getpass输入Python 3

2024-04-26 00:34:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建密码输入。我知道getpass.getpass但是当我把它放到空闲状态时,它会出现一个错误,说“密码可能会被回显”。

我的代码:

import getpass

p = getpass.getpass()

print("You entered:") + p

这可能不起作用,因为我使用的是Python3.2.3


Tags: 代码importyou密码状态错误空闲print
2条回答

如果getpass()有问题[而且很多人都有问题],请尝试easygui ver中的passwordbox。0.96分。不过,我强烈反对0.98。它在运行代码时产生了一个错误,与0.96相反,0.96工作得非常出色,根据需要,只在框中显示星号。

python setup.py install

from easygui import passwordbox
password = passwordbox("PASSWORD:")

^{}文档中:

Note If you call getpass from within IDLE, the input may be done in the terminal you launched IDLE from rather than the idle window itself.

以及:

If echo free input is unavailable getpass() falls back to printing a warning message to stream and reading from sys.stdin and issuing a GetPassWarning.

因此,可能您的空闲环境中没有可用的echo free input(例如,您没有从shell启动它)。

相关问题 更多 >