Я пытаюсь создать информационную систему для студентов, информация будет храниться в текстовом файле и будет отображаться в виде таблицы.
Функция кнопки «Отправить»:
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 = 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)
Я пробовал:
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
И:
for stndt in table.item():
if idEntry.get() == stndt:
messagebox.showerror("ERROR", "You can't use the same ID number!")
print(stndt)
Подробнее здесь: https://stackoverflow.com/questions/797 ... -id-number