Reputation: 13
I am using a Listbox in order to display some text when I press a button. However, when I press this button again to re-display, it just puts the text below the original text in the listbox
. I have searched for ways to fix this problem but I cannot seem to find one that works for my specific program. The point of my program is to check a password entered by a user.
Here is my code:
#!/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()
When I enter a first password: First Password Entry
When I enter a second password: Second Password Entry
After entering the second password it just puts the next set of checks below the old ones, so how would I make it that the old set gets deleted when entering the second password? Thanks.
Upvotes: 0
Views: 2841