Vegaseat did one a while ago and posted it http://www.daniweb.com/forums/thread198855.html I think most GUI toolkits include methods to do this.
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()
And on Linux, we can use termios, but don't know if is it also available on Solaris.
import termios, sys, os
#import termios, TERMIOS, sys, os
TERMIOS = termios
def getkey():
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
new[6][TERMIOS.VMIN] = 1
new[6][TERMIOS.VTIME] = 0
termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
c = None
try:
c = os.read(fd, 1)
finally:
termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
return c
if __name__ == '__main__':
print "type something...'q' to quit"
s = ''
while 1:
c = getkey()
if c == 'q':
break
print "captured key", c, ord(c)
s = s + c
print "Password =", s