Hey guys...

I would like to know how we can mask text input...I have read in some websites that we have to turn off the 'echo', but as far as I know, it only works in Linux....so what the alternative for Windows? I tried the getpass.getpass but in vain! :(

Please help

Thanks

Here is the poop ...

# getpass works in the Windows Console itself
# and does not echo the password as it is entered:
# (does not work in DrPython or IDLE output windows)

import getpass

#usr = getpass.getuser()
usr = "Frank"
pwd = getpass.getpass("enter password for user %s: " % usr)
print usr, pwd

Make sure you run this in the DOS console window!

It doesn't work even though I run it in the DOS Console window! It just pops up and then closes....(even when I modified the code with the time module)..

In IDLE, when I run it, it says "'module' not found"

Most GUI toolkits have a password entry, here is an example using Tkinter ...

# Tkinter program to show password entry

import Tkinter as tk

root = tk.Tk()

def show_pw():
    pw = pw_entry.get()
    label2['text'] = pw
    

label1 = tk.Label(root, text="Enter password for user Frank: ")
# shows only * when entering a password
pw_entry = tk.Entry(root, show="*")
# cursor here
pw_entry.focus()
# click on button to show the password
button = tk.Button(root, text='show password', command=show_pw)
# label to show result
label2 = tk.Label(root)

# widget layout, stack vertical
label1.pack()
pw_entry.pack()
button.pack()
label2.pack()

# start the event loop
root.mainloop()

It doesn't work even though I run it in the DOS Console window! It just pops up and then closes....(even when I modified the code with the time module)..

In IDLE, when I run it, it says "'module' not found"

Works well on my Linux/Ubuntu computer. I code with the Geany IDE and that one uses the console/terminal window as an output window, but keeps it open until you press the Return key.

You may have to add a wait line to the end of your code otherwise:

# your code here

raw_input("Press enter to go on ... ")
# with Python3 use
#input("Press enter to go on ... ")
This article has been dead for over six months. Start a new discussion instead.