tkinter input form

Solutions on MaxInterview for tkinter input form by the best coders in the world

showing results for - "tkinter input form"
Bear
27 Jun 2018
1from tkinter import * 
2
3def save_info():
4    firstname_info = firstname.get()
5    lastname_info = lastname.get()
6    age_info = age.get()
7    
8    print(firstname_info,lastname_info,age_info)
9    
10    file = open("user.txt","w")
11    
12    file.write("Your First Name " + firstname_info)
13    
14    file.write("\n")
15    
16    file.write("Your Last Name " + lastname_info)
17    
18    file.write("\n")
19    
20    file.write("Your Age " + str(age_info))
21    
22    file.close()
23    
24    
25
26app = Tk()
27
28app.geometry("500x500")
29
30app.title("Python File Handling in Forms")
31
32heading = Label(text="Python File Handling in Forms",fg="black",bg="yellow",width="500",height="3",font="10")
33
34heading.pack()
35
36firstname_text = Label(text="FirstName :")
37lastname_text = Label(text="LastName :")
38age_text = Label(text="Age :")
39
40firstname_text.place(x=15,y=70)
41lastname_text.place(x=15,y=140)
42age_text.place(x=15,y=210)
43
44firstname = StringVar()
45lastname = StringVar()
46age = IntVar()
47
48first_name_entry = Entry(textvariable=firstname,width="30")
49last_name_entry = Entry(textvariable=lastname,width="30")
50age_entry = Entry(textvariable=age,width="30")
51
52first_name_entry.place(x=15,y=100)
53last_name_entry.place(x=15,y=180)
54age_entry.place(x=15,y=240)
55
56button = Button(app,text="Submit Data",command=save_info,width="30",height="2",bg="grey")
57
58button.place(x=15,y=290)
59
60
61mainloop()