How to hide/show password with Custom Tkinter?

Question:

Can’t find any info about how to make password visible or hide with Custom Tkinter.

import tkinter as tk
import customtkinter

def toggle_password():
    if txt.cget('show') == '':
        txt.config(show='*')
    else:
        txt.config(show='')

root = tk.Tk()
root.geometry("200x200")

txt = customtkinter.CTkEntry(root, width=20)
txt.pack()

toggle_btn = customtkinter.CTkButton(root, text='Show Password', width=15, command=toggle_password)
toggle_btn.pack()

root.mainloop()
Asked By: Boris Sharikov

||

Answers:

The show method isn’t directly supported by the CtkEntry widget. You will need to configure the Entry widget that is internal to the CtkEntry widget.

def toggle_password():
    if txt.entry.cget('show') == '':
        txt.entry.config(show='*')
    else:
        txt.entry.config(show='')
Answered By: Bryan Oakley

All you need to do it change the .config() to .configure(). The below code will run fine.

import tkinter as tk
import customtkinter

def toggle_password():
    if txt.cget('show') == '':
        txt.configure(show='*')
    else:
        txt.configure(show='')
Answered By: Tommy-python