I'm trying to make a Student Information System, the information will be stored in a text file, and will be shown through a table.
Submit button function:
def submit():
if idEntry.get() == "" or nameEntry.get() == "" or yearEntry.get() == "" or courseEntry.get() == "":
messagebox.showerror("ERROR", "Student information can't be left in a blank!")
return
if not idEntry.get().isdigit():
messagebox.showerror("ERROR", "Student ID number must be a digit!")
return
elif not yearEntry.get().isdigit():
messagebox.showerror("ERROR", "Student year must be a digit!")
return
with open("sis.txt", "a") as f:
f.write(f"{idEntry.get()},{nameEntry.get()},{yearEntry.get()},{courseEntry.get()}\n")
f.close
messagebox.showinfo("Successful", "Student is enrolled")
student = [idEntry.get(),nameEntry.get(),yearEntry.get(),courseEntry.get()]
table.insert(parent='',index=0,values=student)
Table:
table = ttk.Treeview(window, columns=('idnum','name','year','course'), show='headings')
table.heading('idnum', text='ID Number')
table.heading('name', text='Name')
table.heading('year', text='Year')
table.heading('course', text='Course')
table.pack(fill='both',expand=True,padx=10,pady=10)
table.bind('<<TreeviewSelect>>', item_select)
with open("sis.txt", "r") as f:
for line in f:
data = line.strip().split(",")
student = (data[0],data[1],data[2],data[3])
table.insert(parent='',index=0,values=student)
I have tried:
with open("sis.txt", "a") as f:
for stdnt in table:
if idEntry.get() == stdnt:
messagebox.showerror("ERROR", "You can't use the same ID number!")
return
And:
for stndt in table.item():
if idEntry.get() == stndt:
messagebox.showerror("ERROR", "You can't use the same ID number!")
print(stndt)
*Entry,messageboxtable/your data ultimately being stored?