我已经安排了一段代码(这对您来说并不完美,但是…)基于你的,至少对你的进步有用。我想你的代码不完整,也有一些错误。您必须在小部件中配置show参数。更改show var不会对小部件产生任何影响。
你必须使用表格
widget['show'] = somevalue
。或者
.configure
小部件方法。对于这两者,您都需要一个小部件参考。如果在创建小部件的同一行中对其进行网格化,
grid
不会归还任何东西,所以你把它弄松了。将其分为两步,并在创建时保留小部件的引用(第一步)。
entry
实际上被称为
Entry
。这些都是我看到的最可能的错误。
from tkinter import Button, Checkbutton, Entry, Tk, IntVar
root = Tk()
showPassword = IntVar()
show = None
def apply():
print(showPassword.get())
sspass = showPassword.get()
print(type(sspass))
if sspass == 1:
Password['show'] = ""
elif sspass == 0:
Password['show'] = "*"
Password.update()
spB = Checkbutton(root, text="Show Password", variable=showPassword).grid(row=10, column=1)
applyButton = Button(root, text="Apply", command=apply).grid(column=1, row=5)
Password = Entry(root, show=show)
Password.grid(row=3, column=1)
root.mainloop()