python_by_example/tkgui/sols_124-132/sol_08.py
2023-11-17 13:26:09 -03:00

42 lines
1.0 KiB
Python

from tkinter import *
import csv
def create_new():
file = open("/tmp/ages.csv", "w")
file.close()
def save_list():
with open("/tmp/ages.csv", "a") as file:
name = name_box.get()
age = age_box.get()
newrecord = name + ", " + age + "\n"
file.write(str(newrecord))
name_box.delete(0, 'end')
age_box.delete(0, 'end')
name_box.focus()
window = Tk()
window.title("Lista Personas")
window.geometry("400x100")
label1 = Label(text="Ingresa un 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="Ingresa la 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)
button1 = Button(text="Crear nuevo CSV", command=create_new)
button1.place(x=250, y=20, width=100, height=25)
button2 = Button(text="Agregar al CSV", command=create_new)
button2.place(x=250, y=50, width=100, height=25)
window.mainloop()