我不知道如何删除输入框PassEnter
的文本。这是我得到的错误:
那是错误:在check_length中 self.PassEnter.delete(0,END)AttributeError:“事件”对象没有属性“ PassEnter”
from tkinter import *
import random
import time
from tkinter import END
def __init__(self, button, master, event):
pass
a=["red","blue","green","cyan","lime","light
blue","orange","yellow","gold","silver","purple","pink","brown"]
def change_color():
tk.configure(background=random.choice(a))
tk.update()
该函数出错:
def check_length(self):
if len(g) < 8:
self.L2 = Label(tk, bg="blue", fg="red", text="The password must be
8 or longer", font=("Arial", 14))
self.L2.pack(anchor=NW)
self.PassEnter.delete(0, END)
SV.update()
tk.update()
time.sleep(0.01)
tk.mainloop()
这是代码的开头:
tk = Tk()
tk.title("Cosa")
tk.geometry("500x500")
tk.wm_attributes("-topmost", 1)
tk.configure(background=random.choice(a))
L1 = Label(tk, fg="black", text="Password:", font=("Times new roman", 15))
L1.pack(anchor=NW)
这是要检查的“输入”框:
SV = StringVar()
BV = BooleanVar()
PassEnter = Entry(tk, bg="white", fg="black", bd=5)
PassEnter.pack(side="top", anchor=NW)
g=PassEnter.get()
PassEnter.bind("<KeyPress-Return>", check_length)
btn = Button(tk, bg="black", fg="white", text="Change background color",
command=change_color)
btn.pack(side="bottom", anchor=SE)
tk.update()
time.sleep(0.01)
tk.mainloop()