Wie kann sichergestellt werden, dass ein Benutzer keinen Eintrag einreichen kann, wenn er dieselbe ID-Nummer hat?Python

Python-Programme
Anonymous
 Wie kann sichergestellt werden, dass ein Benutzer keinen Eintrag einreichen kann, wenn er dieselbe ID-Nummer hat?

Post by Anonymous »

Ich versuche, ein Studenteninformationssystem zu erstellen. Die Informationen werden in einer Textdatei gespeichert und in einer Tabelle angezeigt.
Funktion der Schaltfläche „Senden“:

Code: Select all

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)
Tabelle:

Code: Select all

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('', 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)
Ich habe versucht:

Code: Select all

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
Und:

Code: Select all

for stndt in table.item():
if idEntry.get() == stndt:
messagebox.showerror("ERROR", "You can't use the same ID number!")
print(stndt)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post