from tkinter import *

def save_info():
    firstname_info=firstname.get()
    lastname_info=lastname.get()
    age_info=str(age.get())
    #print(firstname_info, lastname_info, age_info)
    file = open("users.txt", "a")

    file.write(firstname_info)
    file.write(lastname_info)
    file.write(age_info)

    file.flush()
    file.close()
    print("User ", firstname_info, lastname_info, "has been registered")

    firstname_entry.delete(0, END)
    lastname_entry.delete(0, END)
    age_entry.delete(0, END)
    

root=Tk()
root.geometry("500x800")
root.title("Form Example")

heading=Label(text="My Form", bg="grey", fg="black", width="500", height="3")
heading.pack()

firstname_txt=Label(text="First Name: ")
lastname_txt=Label(text="Last Name: ")
age_txt=Label(text="Age: ")

firstname_txt.place(x=15, y=70)
lastname_txt.place(x=15,y=140)
age_txt.place(x=15,y=210)

firstname=StringVar()
lastname=StringVar()
age=IntVar()

firstname_entry=Entry(textvariable=firstname, width="30")
lastname_entry=Entry(textvariable=lastname, width="30")
age_entry=Entry(textvariable=age, width="5")

firstname_entry.place(x=15, y=100)
lastname_entry.place(x=15, y=170)
age_entry.place(x=15, y=240)

register=Button(text="Register", width="10", command=save_info)
register.place(x=0, y=300)
