python实现在控制台输入密码不显示的方法

yipeiwu_com6年前Python基础

本文实例讲述了python实现在控制台输入密码不显示的方法。分享给大家供大家参考。具体实现方法如下:

import console;
namespace console{
  //控制台读取密码,并显示星号
  getPassword = function(){
    var tstr = {};
    var input = kbRead(true);
    while( input.wVirtualKeyCode != 0xD/*_VK_ENTER*/ ){
      if( input.uChar.asciiChar ){
        ..table.push(tstr,input.uChar.asciiChar);
        if( input.uChar.asciiChar > 0x80){
          ..table.push(tstr,kbRead(true).uChar.asciiChar);
        }
        ..io.stdout.write("*");
      }
      input = kbRead(true);
    }
    ..io.stdout.write('\n');
    return ..string.pack(tstr);
  }
}
io.open();
io.stdout.write("请输入密码:");
var pwd = console.getPassword();
import win;
win.msgbox(pwd,"密码");

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python从子线程中获得返回值的方法

如下所示: # coding:utf-8 import time from threading import Thread def foo(number): time.s...

python感知机实现代码

python感知机实现代码

本文实例为大家分享了python感知机实现的具体代码,供大家参考,具体内容如下 一、实现例子 李航《统计学方法》p29 例2.1 正例:x1=(3,3), x2=(4,3), 负例:x3...

Python实现简单遗传算法(SGA)

Python实现简单遗传算法(SGA)

本文用Python3完整实现了简单遗传算法(SGA) Simple Genetic Alogrithm是模拟生物进化过程而提出的一种优化算法。SGA采用随机导向搜索全局最优解或者说近似...

Python小白必备的8个最常用的内置函数(推荐)

Python给我们内置了大量功能函数,官方文档上列出了69个,有些是我们是平时开发中经常遇到的,也有一些函数很少被用到,这里列举被开发者使用最频繁的8个函数以及他们的详细用法 print...

Python定义二叉树及4种遍历方法实例详解

Python定义二叉树及4种遍历方法实例详解

本文实例讲述了Python定义二叉树及4种遍历方法。分享给大家供大家参考,具体如下: Python & BinaryTree 1. BinaryTree (二叉树) 二叉树是有限个元素的...