Show and hide tkinter Entry password

Show and hide tkinter Entry password

Don't talk nonsense, just look at the effect, okay? !

First look at the animation:

Please add a picture description

code:

import tkinter

app = tkinter.Tk()
app.geometry("480x360+500+100")

pwd = tkinter.Entry(show="*")
pwd.pack()

boolvar = tkinter.BooleanVar()
boolvar.set(0) #0隐藏 1显示

showpwd = tkinter.Radiobutton(text="显示密码", variable=boolvar, value=1)
showpwd.pack()

hidepwd = tkinter.Radiobutton(text="隐藏密码", variable=boolvar, value=0)
hidepwd.pack()

def dofn():
    if boolvar.get():
        pwd.config(show="")
    else:
        pwd.config(show="*")

showpwd.config(command=lambda:dofn())
hidepwd.config(command=lambda:dofn())

app.mainloop()

----END----
Learning only.

Guess you like

Origin blog.csdn.net/qq_52722885/article/details/129529467