Удалить текст в поле ввода - PullRequest
0 голосов
/ 09 марта 2019

Я не знаю, как удалить текст из поля ввода PassEnter. Вот ошибка, которую я получаю:

Это ошибка: в check_length self.PassEnter.delete (0, END) AttributeError: у объекта 'Event' нет атрибута '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()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...