Answers for "python tkinter save entry data in txt file"

1

python tkinter save entry data in txt file

# Save data from entry widget to a text file:
from tkinter import *

def save_data():
  name_info = name.get()

  f = open("text_file.txt", "w")
  f.write(name_info + "\n")
  f.close()

root = Tk()

name = StringVar()

Entry(root, textvariable=name).pack()

Button(root, text='Save Data', command=lambda:save_data()).pack()

root.mainloop()
Posted by: Guest on May-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language