1

I am trying to make a little log in program. But i am not sure if there is a way to replace the "password" with stars when you type the password. This is my code:

from tkinter import *

def callback():
print("hi")

top = Tk()
L1 = Label(top, text="User Name")
L1.grid(row=0, column=0)
E1 = Entry(top, bd = 5)
E1.grid(row=0, column=1)

L1 = Label(top, text="Password")
L1.grid(row=1, column=0)
E1 = Entry(top, bd = 5)
E1.grid(row=1, column=1)

MyButton1 = Button(top, text="Submit", width=10, command=callback)
MyButton1.grid(row=3, column=1)

top.mainloop()

3 Answers 3

17

Use the show="*" option. e.g.

E1 = Entry(top, bd = 5, show="*")
Sign up to request clarification or add additional context in comments.

1 Comment

That was easier than i thought it would be. Thanks a lot mate
1

You can create an entry this way And hide it like a password

from tkinter import *

def show():
    entry.configure(show='')
    check.configure(command=hide, text='hide password')

def hide():
    entry.configure(show='*')
    check.configure(command=show, text='show password')


window = Tk()
window.title('The Title')
window.geometry('400x400')
window.resizable(False, False)

entry = Entry(window, show='*')
entry.pack()

check = Checkbutton(window, text='show password',
        command=show)
check.pack()


window.mainloop()

1 Comment

Nice start, but Program need more work as is. Return does not exit, and return the password, nor is there an enter button.
0
from getpass import getpass
getpass()

There are various alternatives to this floating around the web that have been altered to echo something, like asterisks. Unfortunately they tend to be platform-specific, unlike getpass().

1 Comment

This solution definitely will not work with a Tkinter entry widget. It's the wrong solution for this specific problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.