
def my_show():
if(c_v1.get()==1):
e1.config(show='') # display the chars
else:
e1.config(show='*')# hide the chars using mask
e1 = tk.Entry(my_w,font=font1,show='*',textvariable=e1_str)
e1.grid(row=1,column=2,padx=5,pady=5)
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 Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.