Python GUI Tkinter Form Submit Data to Text File Using File Handling

Python GUI Tkinter Form Submit Data to Text File Using File Handling

Welcome folks I am back with another blog post. In this blog post I will be talking about tkinter framework in which we will be creating a simple form and in that form we will have 3 fields firstname lastname and age and then we have a button after hitting the button we will save these details to a text file using text handling in tkinter. The screenshots of the application is given below.





Source Code:


from tkinter import * 

def save_info():
    firstname_info = firstname.get()
    lastname_info = lastname.get()
    age_info = age.get()
    file = open("user.txt","w")
    file.write("Your First Name " + firstname_info)
    file.write("Your Last Name " + lastname_info)
    file.write("Your Age " + str(age_info))

app = Tk()


app.title("Python File Handling in Forms")

heading = Label(text="Python File Handling in Forms",fg="black",bg="yellow",width="500",height="3",font="10")


firstname_text = Label(text="FirstName :")
lastname_text = Label(text="LastName :")
age_text = Label(text="Age :"),y=70),y=140),y=210)

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

first_name_entry = Entry(textvariable=firstname,width="30")
last_name_entry = Entry(textvariable=lastname,width="30")
age_entry = Entry(textvariable=age,width="30"),y=100),y=180),y=240)

button = Button(app,text="Submit Data",command=save_info,width="30",height="2",bg="grey"),y=290)



READ  Join 10 Kali Linux Whatsapp Group Invite Links For Linux OS Developers and Programmers in 2021

In this block of code we have written code for file handling for tkinter form. In this block of code we are submitting data to a text file with the following details firstname lastname and age.

Leave a Reply