How would I manipulate an entry widget so that it hides the entered characters behind asterisks? like this:

Typed: PassWord
Displayed as typing occurs: ********
I'm trying to make a dialog box module, for use in some future programs. I want the user to be the only one to know what he is typing in case of eavesdroppers reading over the shoulder as it is entered. Here's the current code, to make the box:

# file: MyPassBox.py
loginId={}
#import modules:
from Tkinter import *
#define main window
class main:
    def __init__(self, master):
        self.master = root
        self.master.title('Username and Password?')
        self.master.geometry('300x100+300+450')
        self.master.labelUser = Label(self.master, text = 'Username?')
        self.master.labelUser.grid(row=0, column=0)
        self.master.entryUser = Entry(self.master)
        self.master.entryUser.grid(row=0, column=1)
        self.master.labelPass = Label(self.master, text = 'Password?')
        self.master.labelPass.grid(row=1, column=0)
        self.master.entryPass = Entry(self.master)
        self.master.entryPass.grid(row=1, column=1)
        self.button_OK=Button(self.master, text='Submit', command=self.submit)
        self.button_OK.grid(row=2, column=0)
        self.button_cancel=Button(self.master, text='Cancel', command=self.cancel)
        self.button_cancel.grid(row=2, column=3)
        
        self.master.mainloop()
    def submit(self):
        print 'submit'
    def cancel(self):
        self.master.destroy()
root = Tk()
main(root)

Can you help me?

Recommended Answers

All 4 Replies

As far as I know only wxPython has a password option, the Tkinter Entry widget does not. An easy way to get around this, is to give the password entry widget a bg="yellow" and fg="white". This will be very hard to see for a bystander, as you type in the password, after the return key has been pressed clear the contents. If you want to be tricky, rather then clear, put in a silly password.

If you don't want to show your password in your code see:
http://www.daniweb.com/techtalkforums/post220840-56.html

Actually, Tkinter has a 'show' option that allows you to specify which character shows in the box. I've used it for password boxes:

my_entry["show"] = "*"

Jeff

Actually, Tkinter has a 'show' option that allows you to specify which character shows in the box. I've used it for password boxes:

my_entry["show"] = "*"

Jeff

Thanks, jeff, it now does exactly what I want.

Thanks Jeff, learned something new!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.