我创建了一个带有show参数的密码输入小部件,我创建了一个复选框来显示用户在条目小部件中输入的密码。我怎么能这样做 我想在用户点击复选框列表时显示密码
答案 0 :(得分:1)
这是一个切换条目内容字符替换的示例。我只能猜测这就是你想要的东西:
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
except ImportError:
import Tkinter as tk
def toggle_password():
global entry, checkbutton
if checkbutton.var.get():
entry['show'] = "*"
else:
entry['show'] = ""
if __name__ == '__main__':
root = tk.Tk()
entry = tk.Entry(root)
entry.default_show_val = entry['show']
entry['show'] = "*"
checkbutton = tk.Checkbutton(root,
text="Hide password",
onvalue=True,
offvalue=False,
command=toggle_password)
checkbutton.var = tk.BooleanVar(value=True)
checkbutton['variable'] = checkbutton.var
entry.pack()
checkbutton.pack()
tk.mainloop()