How to create a password entry field using Tkinter

后端 未结 4 1732
后悔当初
后悔当初 2020-11-29 02:44

I am trying to code a login window using Tkinter but I\'m not able to hide the password text in asterisk format. This means the password entry is plain text, which has to be

相关标签:
4条回答
  • 2020-11-29 03:16

    If you don't want to create a brand new Entry widget, you can do this:

    myEntry.config(show="*");
    

    To make it back to normal again, do this:

    myEntry.config(show="");
    

    I discovered this by examining the previous answer, and using the help function in the Python interpreter (e.g. help(tkinter.Entry) after importing (from scanning the documentation there). I admit I just guessed to figure out how to make it normal again.

    0 讨论(0)
  • 2020-11-29 03:18

    Here's a small, extremely simple demo app hiding and fetching the password using Tkinter.

    #Python 3.4 (For 2.7 change tkinter to Tkinter)
    
    from tkinter import * 
    
    def show():
        p = password.get() #get password from entry
        print(p)
    
    
    app = Tk()   
    password = StringVar() #Password variable
    passEntry = Entry(app, textvariable=password, show='*').pack() 
    submit = Button(app, text='Show Console',command=show).pack()      
    app.mainloop() 
    

    Hope that helps!

    0 讨论(0)
  • 2020-11-29 03:25
    widget-name = Entry(parent,show="*")
    

    You can also use a bullet symbol:

    bullet = "\u2022" #specifies bullet character
    widget-name = Entry(parent,show=bullet)#shows the character bullet
    
    0 讨论(0)
  • 2020-11-29 03:28

    A quick google search yielded this

    widget = Entry(parent, show="*", width=15)
    

    where widget is the text field, parent is the parent widget (a window, a frame, whatever), show is the character to echo (that is the character shown in the Entry) and width is the widget's width.

    0 讨论(0)
提交回复
热议问题