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 avoided. Any idea how to do it?
5 Answers
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.

- 26,308
- 17
- 56
- 95
-
This is helpful as far as it goes. While the OP didn't mention this, can you speak to whether `show='*'` also prevents copy/paste? – Adrian Keister Apr 08 '19 at 18:28
-
2I can speak to this on a Mac using Python 3.7, at any rate: copying only copies the *'s, so the security seems adequate for most purposes. – Adrian Keister Apr 08 '19 at 19:15
-
1You know, it's been a while, so I'm not even sure this was for python 3 when I wrote this answer. I guess it depends on how the operating system renders password fields, if it has them natively. – Federico klez Culloca Apr 09 '19 at 07:10
-
1And I can speak to this on a Linux (Ubuntu) using Python 3.8. Now we just need a testimony from a Windows user :-). – Sylvester Kruin Oct 19 '21 at 20:38
-
1I'm a Windows 11 user with Python 3.11.4 and can confirm copying the field copies a bunch of asterisks here as well. – Dariush Mazlumi Aug 05 '23 at 13:27
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.

- 4,387
- 4
- 34
- 56
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

- 4,387
- 4
- 34
- 56

- 131
- 1
- 4
-
This didn't work for me; not sure what I am doing wrong, or if it just doesn't work – Captain Fantastic Dec 13 '16 at 12:21
-
If you're using Python 3.x, you can actually just type the bullet symbol instead of the Unicode code. Make sure your file is UTF-8 encoded, however. @CaptainFantastic On Linux, you can sometimes type Unicode characters by typing Ctrl+shift+m and then typing the code. Or copy from the character map, or use a compose key sequence. – Brōtsyorfuzthrāx Feb 09 '19 at 20:07
-
1
-
You can also use the "black circle": `●`, which is typical for some Linux systems at least. For example: `bullet = "\u25CF"`. – Sylvester Kruin Oct 19 '21 at 20:43
-
@CaptainFantastic It probably didn't work because there were hyphens in the variable names as Asara mentioned. I edited Nathan Green's answer to fix that. – Brōtsyorfuzthrāx Dec 08 '22 at 01:50
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='*')
submit = Button(app, text='Show Console',command=show)
passEntry.pack()
submit.pack()
app.mainloop()
Hope that helps!

- 3,077
- 3
- 26
- 32
-
both `passEntry` and `submit` contains `None` after calling `pack()`, you need to assigning variables first and then call the `pack` manager. – R__raki__ Jul 22 '19 at 05:54
I was looking for this possibility myself. But the immediate "hiding" of the entry did not satisfy me. The solution I found in the modification of a tk.Entry, whereby the delayed hiding of the input is possible:
Basically the input with delay is deleted and replaced
def hide(index: int, lchar: int):
i = self.index(INSERT)
for j in range(lchar):
self._delete(index + j, index + 1 + j)
self._insert(index + j, self.show)
self.icursor(i)
and the keystrokes are written into a separate variable.
def _char(self, event) -> str:
def del_mkey():
i = self.index(INSERT)
self._delete(i - 1, i)
if event.keysym in ('Delete', 'BackSpace'):
return ""
elif event.keysym == "Multi_key" and len(event.char) == 2: # windows stuff
if event.char[0] == event.char[1]:
self.after(10, del_mkey)
return event.char[0]
return event.char
elif event.char != '\\' and '\\' in f"{event.char=}":
return ""
elif event.num in (1, 2, 3):
return ""
elif event.state in self._states:
return event.char
return ""
Look for PassEntry.py if this method suits you.

- 71
- 5
-
hi, how do i integrate the code with a `customtkinter` text entry? tried using `class PassEntry(ctk.CTkEntry):` , then replace the `Entry` inside the class with `ctk.CTkEntry` then using `entry_password = PassEntry(master=root,...` but i cant get it to work – k1dr0ck Aug 06 '23 at 06:12
-
also posted my question: https://stackoverflow.com/questions/76844747/password-text-field-for-customtkinter – k1dr0ck Aug 06 '23 at 06:50