how to change 'show' value in 'entry' method of tkinter

Viewed 53

I want to show clear text in the following code if I check a checkbox:

import tkinter as tk
from tkinter import *

root = tk.Tk()

check_btn_var = tk.IntVar()

def check_btn():
    # function to change show value of 'password_entry'

password_entry = Entry(root, font=("Courier", 14), show="*")
password_entry.grid(row=3, column=1, columnspan=3, padx=2, pady=2, sticky=W)

password_checkbutton = Checkbutton(root, text="show password", variable=check_btn_var, onvalue=1, offvalue=0, command=check_btn)
password_checkbutton.grid(row=3, column=2, padx=38, pady=2, sticky=W)

root.mainloop()

for example:-

when we fill password in any website and we have an option to show password. that is what I want to do with this code

1 Answers

Check if the checkbox has been checked. If it has been checked then set show="" else show='*'

def check_btn():

    if check_btn_var.get():
        password_entry['show'] = "" # or password_entry.config(show='')

    else:
        password_entry['show'] = "*"
    
Related