hi everyone...... am designing an interface for security purposes where a user is allowed to enter a password to gain access...
i want when password is entered its ********** that appear on the text box instead of password secret itself so that if someone is looking at the screen he or she won't know the password.

here is my code:....

from Tkinter import *

class Application(Frame):
    """ GUI application . """
    def __init__(self, master):
        """ Initialize the frame. """
        Frame.__init__(self, master)
    def create_widgets(self):
        """ Create button, text, and entry widgets. """
        # create instruction label
        self.inst_lbl = Label(self, text = "Enter password ")
        self.inst_lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W)
        # create label for password
        self.pw_lbl = Label(self, text = "Password: ")
        self.pw_lbl.grid(row = 1, column = 0, sticky = W)
        # create entry widget to accept password
        self.pw_ent = Entry(self,type="password")
        self.pw_ent.grid(row = 1, column = 1, sticky = W)
        # create submit button
        self.submit_bttn = Button(self, text = "Submit", command = self.reveal)
        self.submit_bttn.grid(row = 2, column = 0, sticky = W)
       # create text widget to display message
        self.secret_txt = Text(self, width = 35, height = 5, wrap = WORD)
        # create text widget to display message
        self.secret_txt.grid(row = 3, column = 0, columnspan = 2, sticky = W)

    def reveal(self):
       """ Display message based on password. """
       contents = self.pw_ent.get()
       if contents == "secret":
           app = Application(root)


           message = "That's not the correct password, so I can't share "\
                      "the secret with you."

       self.secret_txt.delete(0.0, END)

       self.secret_txt.insert(0.0, message)

# main
root = Tk()

app = Application(root)


i have tried to use type = 'password' as in many other language but it is not the case for python. can anyone please help me to perform this.
thank you in advance.

Recommended Answers

All 2 Replies

Try the getpass module, something like

import getpass

Use the show="*" attribute. Also, you are not getting any responses because a Google for "tkinter password" will yield more hits than you can deal with. If this isn't homework, use something found on the web that has already been tested (and is probably written by someone with more Tkinter experience-no offense meant since that includes just about everybody in my case).

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.