Show Hide Password of tkinter Entry

Password show and hide in Tkinter

Tkinter display and mask password in an entry box based on Checkbutton click event using show option


We can control to show or hide chars in an Entry widget using click event of a Checkbutton.

Function my_show()

This function based on the Checkbutton status will show or hide the chars of Entry box. Here c_v1 is one IntVar. It will hold the value 1 ( onvalue ) if Checkbutton is checked, otherwise 0
def my_show():
    if(c_v1.get()==1):
        e1.config(show='') # display the chars 
    else:
        e1.config(show='*')# hide the chars using mask

Entry box with option show

e1 = tk.Entry(my_w,font=font1,show='*',textvariable=e1_str)
e1.grid(row=1,column=2,padx=5,pady=5)

Triggering the checkbutton to execute the function

c1 = tk.Checkbutton(my_w,text='Show Password',variable=c_v1,
	onvalue=1,offvalue=0,command=my_show)
Full code is here
from tkinter import *
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("350x100") 
font1=('Times',18,'bold')	
sv = tk.StringVar() # connected to 1st Label and Spinbox
        
l1=tk.Label(my_w,text='Password',font=font1)  
l1.grid(row=1,column=1,padx=10,pady=10)
e1_str=tk.StringVar() # string variable   
e1 = tk.Entry(my_w,font=font1,width=15,show='*',textvariable=e1_str)
e1.grid(row=1,column=2,padx=5,pady=5)
c_v1=IntVar(value=0)
def my_show():
    if(c_v1.get()==1):
        e1.config(show='')
    else:
        e1.config(show='*')

c1 = tk.Checkbutton(my_w,text='Show Password',variable=c_v1,
	onvalue=1,offvalue=0,command=my_show)
c1.grid(row=2,column=1)    
my_w.mainloop()  # Keep the window open
Tkinter Entry Configure Background based on number of Chars entered
Tkinter Text How to Validate user entered data
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer