I'm trying to create a simple customer registration program where a table pops in when I click a button named "saved" using a list that gets updated by doing the same. I'm also making a delete
function that would delete a selected row via mouse click, I tied this function to a callback function that would set the text in a text field (cName
, cEmail
, birthdate
). My problem is that whenever I would click the delete button it shows up an error-- TypeError: delete() missing 1 required positional argument: 'indexPosition' I tried using different passing methods from one function to another but I'm still stumped.
My code:
from tkinter import *
from tkinter import messagebox
import tkinter as tk
at = False
dotcom = False
list = [['ID', 'NAME', 'EMAIL', 'BIRTHDATE']]
ID = 1
storedIndex = 0
def callback(event):
custid.config(state=NORMAL)
custid.delete('1.0', END)
custid.insert(1.0, list[event.widget._values][0])
custid.config(state=DISABLED)
cName.set(list[event.widget._values][1])
cEmail.set(list[event.widget._values][2])
birthdate.set(list[event.widget._values][3])
indexPosition = event.widget._values
delete(indexPosition)
def createTable():
for i in range(len(list)):
for j in range(len(list[0])):
mgrid = tk.Entry(window, width = 10, bg= 'yellow')
mgrid.insert(tk.END, list[i][j])
mgrid._values= i
mgrid.grid (row = i + 5,column = j + 5)
mgrid.bind("<Button-1>", callback)
def delete(indexPosition):
list.pop(indexPosition)
createTable()
def save ():
customerName = False
Email = False
birthday = False
emailCheck = False
finalCheck = False
monthCheck = False
dayCheck = False
yearCheck = False
minorCheck = False
slash = False
monthCheck31 = False
monthCheck30 = False
monthCheck28 = False
global at
global dotcom
global ID
if len(custName.get()) != 0:
labelNameCheck.config(text="First Name Last Name")
customerName = True
else:
labelNameCheck.config(text="!")
if len(custEmail.get()) != 0:
labelEmail.config(text="[a-z]@[a-z].com")
Email = True
else:
labelEmail.config(text="!")
if len(custBday.get()) != 0:
birthdateCheck.config(text="mm/dd/yyyy")
birthday = True
else:
birthdateCheck.config(text="!")
for x in range(len(custBday.get())):
if x == 9:
# Slash Checking
if custBday.get()[2] == "/" and custBday.get()[5] == "/":
slash = True
# Month Checking
if (int(custBday.get()[0:2]) <= 12):
monthCheck = True
# Day of Month Checking
if (int(custBday.get()[0:2]) == 1):
monthCheck31 = True
if (int(custBday.get()[0:2]) == 2):
monthCheck28 = True
if (int(custBday.get()[0:2]) == 3):
monthCheck31 = True
if (int(custBday.get()[0:2]) == 4):
monthCheck30 = True
if (int(custBday.get()[0:2]) == 5):
monthCheck31 = True
if (int(custBday.get()[0:2]) == 6):
monthCheck30 = True
if (int(custBday.get()[0:2]) == 7):
monthCheck31 = True
if (int(custBday.get()[0:2]) == 8):
monthCheck31 = True
if (int(custBday.get()[0:2]) == 9):
monthCheck30 = True
if (int(custBday.get()[0:2]) == 10):
monthCheck31 = True
if (int(custBday.get()[0:2]) == 11):
monthCheck30 = True
if (int(custBday.get()[0:2]) == 12):
monthCheck31 = True
# Day Checking
if monthCheck31 == True and int(custBday.get()[3:5]) <= 31 and int(custBday.get()[0:2]) != 0:
dayCheck = True
elif monthCheck30 == True and int(custBday.get()[3:5]) <= 30 and int(custBday.get()[0:2]) != 0:
dayCheck = True
elif monthCheck28 == True and int(custBday.get()[3:5]) <= 28 and int(custBday.get()[0:2]) != 0:
dayCheck = True
# Minor Checking
if int(custBday.get()[6:8]) == 20 and int(custBday.get()[8:10]) <= 2:
minorCheck = True
if int(custBday.get()[6:8]) == 19 and int(custBday.get()[8:10] <= 99):
minorCheck = True
# Year Checking
if minorCheck == True and int(custBday.get()[6:8]) != 0:
yearCheck = True
if int(custBday.get()[6:8]) > 20:
yearCheck = False
emailInfo = custEmail.get()
if '@' in emailInfo:
at = True
else:
at = False
if '.com' in emailInfo:
dotcom = True
else:
dotcom = False
if at == True and dotcom == True:
emailCheck = True
if monthCheck == True and dayCheck == True and yearCheck == True and slash == True:
finalCheck = True
if customerName == True and Email == True and birthday == True and emailCheck == True and finalCheck == True:
custid.config(state= NORMAL)
initialValue = int(custid.get('1.0', END))
custid.delete('1.0', END)
list.append([ID, custName.get(), custEmail.get(), custBday.get()])
custid.insert(1.0, initialValue + 1)
custid.config(state=DISABLED)
print(list)
createTable()
msgbox("Saved", "Record")
ID = ID + 1
else:
msgbox("Incorrect Info Provided", "Record")
def keyup(e):
global at
global dotcom
for x in range(len(custEmail.get())):
if custEmail.get()[-1] == "@" and x > 1:
at = True
else:
labelEmail.config(text="Bad Email")
if x > 4 and custEmail.get()[-4:] == ".com" and at == True:
dotcom = True
else:
labelEmail.config(text="Bad Email")
if at == True and dotcom == True:
labelEmail.config(text="Good Email")
else:
labelEmail.config(text="Bad Email")
def keyupBdate(e):
for x in range(len(custBday.get())):
monthCheck = False
dayCheck = False
yearCheck = False
minorCheck = False
slash = False
monthCheck31 = False
monthCheck30 = False
monthCheck28= False
if x == 9:
#Slash Checking
if custBday.get()[2] == "/" and custBday.get()[5] == "/":
slash = True
print("Slash Check = Pass")
else:
print("Slash Check = Fail")
#Month Checking
if (int(custBday.get()[0:2]) <= 12):
monthCheck = True
print("MonthCheck = Pass")
else :
print("MonthCheck = Failed")
#Day of Month Checking
if (int(custBday.get()[0:2]) == 1):
monthCheck31 = True
print("Month Days = 31")
if (int(custBday.get()[0:2]) == 2):
monthCheck28 = True
print("Month Days = 28")
if (int(custBday.get()[0:2]) == 3):
monthCheck31 = True
print("Month Days = 31")
if (int(custBday.get()[0:2]) == 4):
monthCheck30 = True
print("Month Days = 30")
if (int(custBday.get()[0:2]) == 5):
monthCheck31 = True
print("Month Days = 31")
if (int(custBday.get()[0:2]) == 6):
monthCheck30 = True
print("Month Days = 30")
if (int(custBday.get()[0:2]) == 7):
monthCheck31 = True
print("Month Days = 31")
if (int(custBday.get()[0:2]) == 8):
monthCheck31 = True
print("Month Days = 31")
if (int(custBday.get()[0:2]) == 9):
monthCheck30 = True
print("Month Days = 30")
if (int(custBday.get()[0:2]) == 10):
monthCheck31 = True
print("Month Days = 31")
if (int(custBday.get()[0:2]) == 11):
monthCheck30 = True
if (int(custBday.get()[0:2]) == 12):
monthCheck31 = True
print ("Month Days = 31")
#Day Checking
if monthCheck31 == True and int(custBday.get()[3:5]) <= 31 and int(custBday.get()[0:2]) != 0:
dayCheck = True
print ("Day Check = Pass")
elif monthCheck30 == True and int(custBday.get()[3:5]) <= 30 and int(custBday.get()[0:2]) != 0:
dayCheck = True
print("Day Check = Pass")
elif monthCheck28 == True and int(custBday.get()[3:5]) <= 28 and int(custBday.get()[0:2]) != 0:
dayCheck = True
print("Day Check = Pass")
else :
birthdateCheck.config(text="Incorrect Date Format")
#Minor Checking
if int(custBday.get()[6:8]) == 20 and int(custBday.get()[8:10]) <= 2:
minorCheck = True
print("Minor Check: Passed")
else:
birthdateCheck.config(text="Invalid Year")
if int(custBday.get()[6:8]) == 19 and int(custBday.get()[8:10] <= 99):
minorCheck = True
print("Minor Check: Passed")
else:
birthdateCheck.config(text="Invalid Year")
#Year Checking
if minorCheck == True and int(custBday.get()[6:8]) != 0:
yearCheck = True
print ("Year Check: Pass \n")
elif minorCheck == False:
birthdateCheck.config(text="You must be 18+ of age to save account")
print("Customer is a Minor")
if int(custBday.get()[6:8]) > 20:
birthdateCheck.config(text="Invalid Year")
else :
birthdateCheck.config(text = "Wrong Date")
if slash == True and monthCheck == True and yearCheck == True and dayCheck == True:
birthdateCheck.config(text = "✓")
def msgbox (msg, titlebar):
messagebox.showinfo(title = titlebar, message=msg)
def products():
window = Tk()
window.title("Products Form")
window.geometry("550x400")
window.configure(bg="orange")
window = Tk()
window.title("Sample Window")
window.geometry("550x400")
window.configure(bg="orange")
menubar = Menu(window)
filemenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Products", command=products)
filemenu.add_command(label="Orders")
filemenu.add_separator()
filemenu.add_command(label="Close", command = window.quit)
window.config(menu=menubar)
labelTitle = Label(window, text="Customer Registration System", width=30, height=1, bg="yellow", anchor= "center")
labelTitle.config(font=("Courier", 10))
labelTitle.grid(column=2, row=1)
labelID = Label(window, text="Customer ID", width = 20, height = 1, bg = "yellow")
labelID.grid(column=1, row=2)
cID = StringVar()
custid = Text(window, width=15, height=1)
custid.grid(column=2, row=2)
custid.insert(1.0, "1")
custid.config(state = DISABLED)
labelNameCheck = Label(window, text="Last Name, First Name", width = 20, height = 1, bg = "yellow")
labelNameCheck.grid(column=3, row=3)
labelName = Label(window, text="Customer Name", width = 20, height = 1, bg = "yellow")
labelName.grid(column=1, row=3)
cName = StringVar()
custName = Entry(window, textvariable = cName)
custName.grid(column=2, row=3)
labelEmail = Label(window, text="Customer Email", width = 20, height = 1, bg = "yellow")
labelEmail.grid(column=1, row=4)
cEmail = StringVar()
custEmail = Entry(window, textvariable = cEmail)
custEmail.grid(column=2, row=4)
custEmail.bind("<KeyRelease>", keyup)
labelEmail = Label(window, text="[a-z]@[a-z].com", width = 20, height = 1, bg = "yellow")
labelEmail.grid(column=3, row=4)
labelBday = Label(window, text="Customer Birthdate", width = 20, height = 1, bg = "yellow")
labelBday.grid(column=1, row=5)
birthdate= StringVar()
custBday = Entry(window, textvariable = birthdate)
custBday.grid(column=2, row=5)
custBday.bind("<KeyRelease>", keyupBdate)
birthdateCheck = Label(window, text="mm/dd/yyyy", width = 20, height = 1, bg = "yellow")
birthdateCheck.grid(column=3, row=5)
savebtn = Button(text = "Save", command = save)
savebtn.grid(column=1)
deletebtn = Button(text = "Delete", command = delete)
deletebtn.grid(column=1)
window.mainloop()