我正在使用列表框,以便在按下按钮时显示一些文本。但是,当我再次按此按钮重新显示时,它只会将文本放在listbox
的原始文本下方。我已经找到了解决这个问题的方法,但我似乎无法找到适用于我的特定程序的方法。我的程序的目的是检查用户输入的密码。
这是我的代码:
#!/usr/bin/env python
#Imports
from tkinter import *
from random import *
import string
#Root And GUI Title
root = Tk()
root.wm_title("Password Checker")
#Top Frame
topFrame = Frame(root)
topFrame.grid(row=0)
#Bottom Frame And Geometry And Check Labels
bottomFrame = Frame(root)
bottomFrame.grid(row=10)
root.geometry("1000x1000")
checkLabel = Label(root)
checkCap = Label(root)
checkLow = Label(root)
checkSymb = Label(root)
checkDig = Label(root)
listbox = Listbox(root)
listbox.grid(row=6, column=1)
#Checker Function
def checker():
if len(passEntry.get()) < 8 or len(passEntry.get()) > 24:
listbox.insert(END, "Invalid Length")
listbox.grid(row=1, column=1)
if len(passEntry.get()) >= 8 and len(passEntry.get()) <= 24:
#checkLabel.config(text="Valid Length")
#checkLabel.grid(row=10, column = 1)
listbox.insert(END, "Valid Length")
cap = re.search("[A-Z]", passEntry.get())
if cap:
#checkCap.config(text="Okay Capitals")
#checkCap.grid(row=11, column = 1)
listbox.insert(END, "Okay Capitals")
else:
#checkCap.config(text="No Capitals")
#checkCap.grid(row=11, column = 1)
listbox.insert(END, "No Capitals")
low = re.search("[a-z]", passEntry.get())
if low:
#checkLow.config(text="Okay Lowercase")
#checkLow.grid(row=12, column = 1)
listbox.insert(END, "Okay Lowercase")
else:
#checkLow.config(text="No Lowercase")
#checkLow.grid(row=12, column = 1)
listbox.insert(END, "No Lowercase")
symb = re.search("[!£$%^&*()]", passEntry.get())
if symb:
#checkSymb.config(text="Okay Symbols")
#checkSymb.grid(row=13, column= 1)
listbox.insert(END, "Okay Symbols")
else:
#checkSymb.config(text="No Symbols")
#checkSymb.grid(row=13, column = 1)
listbox.insert(END, "No Symbols")
dig = re.search("[0-9]", passEntry.get())
if dig:
#checkDig.config(text="Okay Digits")
#checkDig.grid(row=14, column = 1)
listbox.insert(END, "Okay Digits")
else:
#checkDig.config(text="No Digits")
#checkDig.grid(row=14, column = 1)
global noDigits
noDigits = listbox.insert(END, "No Digits")
#Password Entry
passEntryLabel = Label(root, text="Password")
passEntryLabel.grid(row=0, column=3)
passEntry = Entry(root)
PAR = passEntry.get()
passEntry.grid(row=0, column=4)
checkButton = Button(root, text="Check Password", command=checker)
checkButton.grid(row=0, column=7)
#Mainloop
root.mainloop()
输入第一个密码时: First Password Entry
当我输入第二个密码时: Second Password Entry
输入第二个密码后,只需将下一组支票放在旧密码下面,那么在输入第二个密码时,如何将旧套装删除?感谢。