Hide raw_input text?

Fredrik Lundh fredrik at pythonware.com
Wed Aug 13 14:26:17 EDT 2008


tmallen wrote:

> I'm working on a little FTP project to get comfortable with ftplib.
> It's all terminal-based right now, and one issue I'm having is hiding
> password input text. I'd like one of two things to happen with this:
> Either don't show any characters while I'm typing (like $ su), or
> better, a '*' for every character. Is there a way to do this? I'm
> planning on building this into a GUI tool using Tkinter or wxPython,
> so methods using a secret input for those might be helpful as well ( I
> could jump straight into the GUI part).

for console input, use the getpass module:

 >>> import getpass
 >>> getpass.getpass("Password: ")
Password:
'trustno1'

for GUI toolkits, the standard text entry widgets usually support 
password input (e.g. using the show option in Tkinter, the wxTE_PASSWORD 
style in wxPython, etc).

</F>




More information about the Python-list mailing list