Saving Entry Content to a Text File - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Sunday, February 19, 2023

Saving Entry Content to a Text File

 

In this article, I save the content of the entry in a text file.

 


 

 

 

 

 

 

 

 

 

 

Figure 1


 

 

 

 

 

 

 

 

 

 

Figure 2

 


 

 

 

 

 

 

Figure 3

 


 

 

 

 

 

 

 

 

Figure 4

 

 

from tkinter import *

from tkinter import messagebox as MessageBox

 

# Create an instance of tkinter rootdow

 

root = Tk()

root.title("save the contents of a textbox ..bs")

root.geometry("450x400")

 

def open_text():

   openFile = open("D:\person.txt", "r")

   content = openFile.read()

   tBox.insert(END, content)

   openFile.close()

 

def save_text():

   openFile = open("D:\person.txt", "w")

   openFile.write(tBox.get(1.0, END))

   openFile.close()

   MessageBox.showinfo("Information","Record saved successfully " + "\n" + "Kayit basarili bir sekilde kaydedildi")

 

# Creating a text box widget

 

tBox = Text(root, width=50,height=15)

tBox.pack(padx=1,pady=1)

 

openBtn = Button(root, text="Open Text File", command=open_text, width=20,height=2,bg="deepskyblue",fg="white")

openBtn.pack(padx=50,pady=10)

 

# Create a button to save the text

 

saveBtn = Button(root, text="Save File", command=save_text, width=20,height=2,bg="fuchsia",fg="white")

saveBtn.pack(padx=50,pady=10)

 

root.mainloop()

 

Hope to see you soon. Happy coding.


No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...