from tkinter import * import csv def save_list(): file = open('/tmp/ages.csv', 'a') name = name_box.get() age = age_box.get() newrecord = name + ', ' + age + '\n' file.write(str(newrecord)) file.close() def read_list(): name_list.delete(0, 'end') file = list(csv.reader(open('/tmp/ages.csv'))) tmp = [] for row in file: tmp.append(row) x = 0 for i in tmp: data = tmp[x] name_list.insert('end', data) x += 1 window = Tk() window.title("Lista Personas") window.geometry("400x200") label1 = Label(text="Nombre") label1.place(x=20, y=20, width=100, height=25) name_box = Entry() name_box.place(x=120, y=20, width=100, height=25) name_box["justify"] = "left" name_box.focus() label2 = Label(text="Edad") label2.place(x=20, y=50, width=100, height=25) age_box = Entry() age_box.place(x=120, y=50, width=100, height=25) age_box["justify"] = "left" button1 = Button(text="Agregar a archivo", command=save_list) button1.place(x=250, y=20, width=100, height=25) button2 = Button(text="Leer archivo", command=read_list) button2.place(x=250, y=50, width=100, height=25) label3 = Label(text="Registros:") label3.place(x=20, y=80, width=100, height=25) name_list = Listbox() name_list.place(x=120, y=80, width=230, height=100) window.mainloop()