Here is the code, I reworked it to suit your requirements. Feedback will be highly appreciated
from Tkinter import * raiz = Tk() frame = Frame(raiz) out = [] def cadastro(): form = Toplevel(raiz) Label(form, text='Nome: ').grid(column=0, row=0, sticky=E) Label(form, text='Celular: ').grid(column=0, row=1, sticky=E) nome = StringVar() celular = StringVar() a=Entry(form, textvariable=nome, width=15) a.grid(column=1, row=0, sticky=W) Entry(form, textvariable=celular, width=15).grid(column=1, row=1, sticky=W) def onCancel(): form.destroy() def onOk(): with open('outt.txt','w') as txt: txt.write('Name : ' + str(nome.get()) + ' ' + 'Telephone No. : ' + str(celular.get())) onCancel() Button(form, text='OK', command=onOk).grid(column=0, row=2, sticky=E) Button(form, text='Cancel', command=onCancel).grid(column=1, row=2, sticky=W) def listar(): with open('outt.txt','r') as txt_read: print txt_read.read() w = Button(raiz, text='Cadastrar',command=cadastro).grid() x = Button(raiz, text='Listar' , command=listar).grid() raiz.mainloop()
after entering the data, if you clicked on listar, you can see the result on the screen (although you can manually view the data that is saved in the TXT file)
here is a sample:
Name: K-DawG Phone Number: 911
The key here is with as instruction, for more information check out the Codeacademy course in python
using a list, and the insert () method is certainly not the best option for this problem, but if you use my method and write a delimited CSV file, the program may finally be worth it