当前位置:首页 > Python教程 > python技巧

2015/9/13 Python密码输入屏蔽字符

在使用Python的过程中,想输入账号和密码,但是密码会随着输入显示在屏幕上,为了解决这个问题需要用到msvcrt模块

这里是使用代码

            import
              msvcrt, sys


            def
             pwd_input(a):
    
            print
             str(a),
    chars = []
    while True:
        newChar = msvcrt.getch()
        if newChar inrn:
            print‘‘breakelif newChar inb:
            if chars:
                del chars[-1]
                sys.stdout.write(bb)
        else:
            chars.append(newChar)
            sys.stdout.write(*)
    return str(chars)

pwd = pwd_input(‘password:‘)

这样就解决了显示问题。

原文:http://www.cnblogs.com/SRL-Southern/p/4780901.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐